当我用PyQt5设计UI时,在Qt设计器中,它看起来像win10应用程序。但是当我在VS代码中启动一个程序或者只是运行一个文件时,它看起来就像在Windows或7中。如何解决这个问题?我在代码中没有更改样式
import os
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
class UI(QMainWindow):
def __init__(self):
super().__init__()
uic.loadUi(os.path.join(sys.path[0], 'untitled.ui'), self)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = UI()
ex.show()
sys.exit(app.exec())发布于 2022-10-01 18:54:24
您可以使用app.setStyle更改显示样式。要获得系统上可用样式的列表,请尝试如下:
from PyQt5.QtWidgets import QStyleFactory
print(QStyleFactory.keys())在我的系统里我得到:
['Breeze', 'Oxygen', 'Windows', 'Fusion']您可能会在Windows框上得到不同的选择。
要评估不同的风格,请尝试:
app.setStyle('<style name here>')或
app.setStyle(QStyleFactory.create('style name here'))https://stackoverflow.com/questions/73918178
复制相似问题