在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一起工作。 –