在PySide,我试图改变一个简单的GUI窗口(QLabel对象)的整体风格,在PySide文件概述:应用的setStyle到/ QLabel在PySide PyQt的
http://srinikom.github.io/pyside-docs/PySide/QtGui/QStyle.html#detailed-description
那是,如该链接所述,我想使用setStyle
将整个GUI格式更改为其中一种预定义的GUI样式(例如,从Windows
到Cleanlooks
)。 (正如我在下面注意到的,这个目标不同于调整颜色和使用setStyleSheet
,我已经知道该怎么做)。
要开始,我先检查什么风格类型我提供以下信息:
print QtGui.QStyleFactory.keys()
这揭示了许多可用的样式,包括“Cleanlooks”。
二,基于以下三个来源(PySide,ZetCode和Nullege)的文件,我想我的QLabel风格更改为 'Cleanlooks':
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
不幸的是,这什么也没有改变。事实上,我输入的内容并没有改变我的Hello World小部件中的一个像素。不确定是否相关,但是当我打印上一行代码的输出时,我总是得到None
。完整的示例代码位于下方。
我在Windows 7中运行iPython中的Python 2.7。根据回复,这似乎是Windows 7中PyQt4的一个问题,而不仅仅是PySide。
为了更加清晰,我不问如何使用setStyleSheets
来调整我的小部件。这已得到解决体面不已: Styling with classes in Pyside + Python
的代码示例我试过(其他排列我试图显示在评论):
# coding: utf-8
import sys
from PySide import QtGui
class HelloWorldApp(QtGui.QLabel):
def __init__(self):
QtGui.QLabel.__init__(self, "Hello, world!")
self.initUI()
def initUI(self):
QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))
self.show()
def main():
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) #crashes program
qt_app=QtGui.QApplication(sys.argv)
#QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks')) #does nothing
exHell=HelloWorldApp()
sys.exit(qt_app.exec_())
if __name__=="__main__":
main()
你尝试一些其他可用的样式?例如,“plastique”。 – qurban
@ qurban。是的:我尝试了印刷键时列出的每种风格,其中包括 - [u'Windows',u'WindowsXP',u'WindowsVista',u'Motif',u'CDE',u'Plastique', u'Cleanlooks']。我试着用/不用unicode符号(u)。 – neuronet
对于它的价值,我已经与PySide有同样的问题 - 但奇迹般地,它与PyQt一起工作。 –