Qt buttons style varying from ui preview to original window

我与影子孤独终老i 提交于 2019-12-12 03:29:10

问题


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?

The code for buttons used are,

    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")

This is the ui rendering in qt creator.

This is the one when the python file is executed.

My working environment is,

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

回答1:


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")


来源:https://stackoverflow.com/questions/45386146/qt-buttons-style-varying-from-ui-preview-to-original-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!