pythonwindowspyqt6darkmode

Python 3.11 made my pyQT application dark


I'm also learning python and making an application to calculate pile strengh. Last time I used python 3.10 and today I decided to update python to 3.11 and noticed that my application became dark according to the "Windows 10" theme. Dark theme looks cool, but it has some artefacts. I'm making this app for civil engineers who hate dark theme, and I want to turn it light permanently, at least, or make a toggle to switch dark/light theme.

light

dark

I assume, there must be one line which can allow/doesn't allow take system windows' theme.

Googling and GPTing didn't give me a good solution. The penultimate line makes mainWindow with artefacts as well.

artefacts

Thanks in advance.

def main():
    app = QtWidgets.QApplication(sys.argv) # Новый экземпляр QApplication
    # Windows, Fusion, windowsvista
    app.setStyle('Windows')  # меняем стиль на "Windows"
    window = MainWindow() # Создаём объект класса MainWindow
    window.show()  # Показываем окно, красивое
    # window.setStyleSheet("background-color: white; color: black;")
    app.exec()  # и запускаем приложение

Solution

  • Sorry guys, I've found a solution by myself (but IDK what's going on here. One day, I will):

    https://stackoverflow.com/a/74505698/23006884

    This line:

    sys.argv += ['-platform', 'windows:darkmode=1']
    
    darkmode=1  # light theme
    darkmode=2  # dark theme