问题描述
我正在尝试使用 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设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)