zhiyiYo / PyQt-Frameless-Window

A cross-platform frameless window based on pyqt5, support Win32, Linux and macOS.
https://pyqt-frameless-window.readthedocs.io
GNU General Public License v3.0
477 stars 67 forks source link

动态加载ui文件怎么使用无边框窗口 #141

Closed npccpn closed 7 months ago

npccpn commented 9 months ago

动态加载ui文件怎么使用无边框窗口 pyqt5

import sys

from PyQt5 import uic
from PyQt5.QtWidgets import QApplication
from qframelesswindow import FramelessWindow

import login_student

class LoginWindow(FramelessWindow):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = uic.loadUi("ui/login.ui")
        self.ui.setWindowTitle("PyQt-Frameless-Window")
        self.titleBar.raise_()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    login = LoginWindow()
    login.ui.show()
    sys.exit(app.exec_())

我以为是这样,但是运行了还是原来的边框效果orz,求大佬指点QAQ

zhiyiYo commented 8 months ago

你是不是在 ui 文件里面设置了窗口属性?

npccpn commented 8 months ago

我之前那个已经删掉了,重新试了一个新窗口,ui这样写好像更合适?运行之后能看出来最小化最大化和关闭按钮已经变了,但是窗口标题显示不出来,把ui的LayoutTopMargin设置为32也显示不了╥﹏╥除了这个以外其他没有设置什么窗口属性诶


class CheckStudentWidget(FramelessWindow):

    def __init__(self, parent=None):
        super().__init__(parent=parent)
        uic.loadUi("ui/teacher_check.ui", self)
        self.setWindowTitle("PyQt-Frameless-Window")
        self.titleBar.raise_()

if __name__ == '__main__':
    # enable dpi scale
    QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    app = QApplication(sys.argv)
    w = CheckStudentWidget()
    w.show()
    app.exec_()

![image](https://github.com/zhiyiYo/PyQt-Frameless-Window/assets/90997762/9624bdc1-2ba8-4d62-adb4-dc9eb4efcbd6)
npccpn commented 8 months ago

QQ截图20240209175522

Cheukfung commented 8 months ago

把ui文件编译为py再运行吧,反正你都设计好了界面了,参考这个新手模板:https://github.com/Cheukfung/pyqt-fluent-widgets-template

npccpn commented 8 months ago

噢噢好的,主要是我很难确定界面,经常要调试ui╥﹏╥