推荐视频教程:
https://www.bilibili.com/video/BV1LT4y1e72X?p=23&vd_source=7ab611f3afb3d469faad93d3996f99ba
https://build-system.fman.io/qt-designer-download
下载后,点开exe
不推荐:https://www.qt.io/zh-cn/product/ui-design-tools 还会下个IDE,还要下半天
选择Widget(不带菜单,轻量),Default size(默认大小)
拖一堆东西,然后点preview,点Form里的preview就会生成下面的图:
保存在一个新的文件夹和路径
对上面的ui文件,复制属性中的“位置”:F:\PyQt\XZEWorks\后加上文件名:mywindow_pyqt1.ui
在Pycharm端写程序调用这个文件:
- import sys
- from PyQt5.QtWidgets import QApplication
- from PyQt5 import uic
-
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- ui = uic.loadUi("F:\PyQt\XZEWorks\mywindow_pyqt1.ui")
- ui.show()
- app.exec()
运行后得到的结果如下:
装QCandyUi库:
pip install QCandyUi
- import sys
- from PyQt5.QtWidgets import QApplication, QMainWindow
- from PyQt5 import uic
- from QCandyUi.CandyWindow import colorful
-
- @colorful('blueDeep')
- class MainWindow(QMainWindow):
-
- def __init__(self):
- super().__init__() # 初始化父类构造函数
- self.ui = uic.loadUi("F:\PyQt\XZEWorks\mywindow_pyqt1.ui")
- self.setCentralWidget(self.ui) # 将加载的UI设置为中心窗口
-
- def show(self):
- self.ui.show()
-
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- ui = MainWindow()
- ui.show()
- sys.exit(app.exec_())
自己定义一个qss文件,保存在指定位置
然后再在pycharm中调用
- import sys
- from PyQt5.QtWidgets import QApplication
- from PyQt5 import uic
-
- class QSSLoader:
- @staticmethod
- def read_qss_file(qss_file_name):
- with open(qss_file_name, 'r', encoding='UTF-8') as file:
- return file.read()
-
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- ui = uic.loadUi("F:\PyQt\XZEWorks\mywindow_pyqt1.ui")
-
- style_file = 'F:\PyQt\XZEWorks\style.qss'
- style_sheet = QSSLoader.read_qss_file(style_file)
- ui.setStyleSheet(style_sheet)
-
- ui.show()
- sys.exit(app.exec_())
黑不溜秋的,QSS文件没弄好