Qt Designer's preview ui is not the same when it running in python

Aiden :

This is the preview

enter image description here

This is how it looks when it running in python

enter image description here

eyllanesc :

Qt handles various styles that are enabled depending on various flags such as environment variables, and Qt Designer probably uses some styles by default, so the style shown by the preview may be different from the application when it is run.

Analyzing the style it seems to me that Qt Designer uses the "fusion" style, so the solution is to add:

app.setStyle("fusion")

If you want to visualize your design with other styles from Qt Designer you must execute: Form-> Preview in -> style


If you want to know all the styles available in your installation you can run the following:

from PySide2 import QtWidgets

print(QtWidgets.QStyleFactory.keys())

In my case I get the following:

['Breeze', 'bb10dark', 'bb10bright', 'cleanlooks', 'gtk2', 'cde', 'motif', 'plastique', 'Oxygen', 'Windows', 'Fusion']

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=336659&siteId=1