我正在尝试使用 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模板网!