Qt buttons style varying from ui preview to original window(Qt 按钮样式从 ui 预览到原始窗口变化)
问题描述
我正在尝试使用 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 预览到原始窗口变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Qt 按钮样式从 ui 预览到原始窗口变化


基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01