0

When I design a UI with PyQt5, in Qt Designer it looks like win10 app. But when I start a program in VS Code or just run a file, it looks like in Windows Vista or 7. How to fix that? I haven't changed style in the code

import os
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow


class UI(QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi(os.path.join(sys.path[0], 'untitled.ui'), self)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = UI()
    ex.show()
    sys.exit(app.exec())

how it looks in designer

how it really looks

Andrey
  • 1

1 Answers1

0

You can change the display style by using app.setStyle. To get a list of available styles on your system try this:

from PyQt5.QtWidgets import QStyleFactory
print(QStyleFactory.keys())

on my system I get:

['Breeze', 'Oxygen', 'Windows', 'Fusion']

Probably you'll get difference choices on a Windows box.

To evaluate different styles try:

app.setStyle('<style name here>')

or

 app.setStyle(QStyleFactory.create('style name here'))
bfris
  • 5,272
  • 1
  • 20
  • 37
  • `app.setStyle(string)` actually *does* call `setStyle(QStyleFactory.create(string))`, so the second solution, while correct, is actually redundant (except for the rare case for which any of those function is overridden). – musicamante Oct 01 '22 at 19:54