問題描述
我正在嘗試使用 qt creator 和 PyQt5 設計一個虛擬鍵盤,問題是,按鈕在 qt creator 中看起來很現代,當我執行 python 文件時,我的按鈕樣式很舊.如何獲得原始樣式?
I am trying to design a virtual keyboard using qt creator and PyQt5, the problem is, the buttons looked modern in the qt creator and when i executed the python file, I got a very old styling for the buttons. How can i get the original styling?
所用按鈕的代碼是,
self.Q = QtWidgets.QPushButton(self.KEYBOARD)
self.Q.setGeometry(QtCore.QRect(0, 0, 80, 60))
font = QtGui.QFont()
font.setPointSize(20)
self.Q.setFont(font)
self.Q.setObjectName("Q")
這是qt creator中的ui渲染.
This is the ui rendering in qt creator.
這是執行python文件時的那個.
This is the one when the python file is executed.
我的工作環境是,
RELEASE=18.1
CODENAME=serena
EDITION="Cinnamon 64-bit"
DESCRIPTION="Linux Mint 18.1 Serena"
DESKTOP=Gnome
TOOLKIT=GTK
NEW_FEATURES_URL=http://www.linuxmint.com/rel_serena_cinnamon_whatsnew.php
RELEASE_NOTES_URL=http://www.linuxmint.com/rel_serena_cinnamon.php
USER_GUIDE_URL=help:linuxmint
GRUB_TITLE=Linux Mint 18.1 Cinnamon 64-bit
推薦答案
Qt使用QStyle類處理樣式,通常Qt Designer使用樣式融合,所以就這樣顯示,和配置的不匹配操作系統:
Qt handles styles using the QStyle class, usually Qt Designer uses the style fusion, so it shows it that way, and this does not match the one that is configured the OS:
您的情況的解決方案是使用以下代碼配置使用融合樣式的應用程序:
The solution in your case is to configure the application that uses the fusion style with the following code:
app = QApplication(sys.argv)
app.setStyle("fusion")
這篇關于Qt 按鈕樣式從 ui 預覽到原始窗口變化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!