![]() Print('theme_selection not found in config. Print('Found theme_selection in config:' + theme_selection) Theme_selection = settings.value('theme_selection') Print('Checking for theme preference in config') You can use Qsettings to save a preference for which mode like this and restore on start. I was trying to apply this to my fbs based app and found the below easily allowed me to style the app by applying it to the AppContext class AppContext(ApplicationContext):ĭark_tColor(QPalette.Window, QColor(53, 53, 53))ĭark_tColor(QPalette.WindowText, Qt.white)ĭark_tColor(QPalette.Base, QColor(35, 35, 35))ĭark_tColor(QPalette.AlternateBase, QColor(53, 53, 53))ĭark_tColor(QPalette.ToolTipBase, QColor(25, 25, 25))ĭark_tColor(QPalette.ToolTipText, Qt.white)ĭark_tColor(QPalette.Text, Qt.white)ĭark_tColor(QPalette.Button, QColor(53, 53, 53))ĭark_tColor(QPalette.ButtonText, Qt.white)ĭark_tColor(QPalette.BrightText, Qt.red)ĭark_tColor(QPalette.Link, QColor(42, 130, 218))ĭark_tColor(QPalette.Highlight, QColor(42, 130, 218))ĭark_tColor(QPalette.HighlightedText, QColor(35, 35, 35))ĭark_tColor(QPalette.Active, QPalette.Button, QColor(53, 53, 53))ĭark_tColor(QPalette.Disabled, QPalette.ButtonText, Qt.darkGray)ĭark_tColor(QPalette.Disabled, QPalette.WindowText, Qt.darkGray)ĭark_tColor(QPalette.Disabled, QPalette.Text, Qt.darkGray)ĭark_tColor(QPalette.Disabled, QPalette.Light, QColor(53, 53, 53)) If you're interested what the above changes look like, I created an example PyQt5 app with a dark theme. ![]() The nice thing about this is that it introduces no external dependencies. tColor(QPalette.HighlightedText, Qt.black) tColor(QPalette.AlternateBase, QColor(53, 53, 53)) # Now use a palette to switch to dark colors: # Force the style to be the same on all OSs: But you can quite easily create one yourself with the following code: from PyQt5.QtCore import Qt This allows users to dynamically change the theme of an application developed with PyQt5 (or using analogous logic in C++, Qt5) to either a light or dark theme.ĭisclaimer: Obviously I am the maintainer. Light_(lambda: toggle_stylesheet(":/light.qss"))ĭark_btn = QPushButton("Toggle dark.", parent)ĭark_(lambda: toggle_stylesheet(":/dark.qss")) Light_btn = QPushButton("Toggle light.", parent) # more logic for creating top-level widgets, application logic. Now we can add generic application logic that can use this function in a signal/slot mechanism (using a lambda as a convenient wrapper, if needed, to provide the path to the stylesheet toggler): # add logic for setting up application Raise RuntimeError("No Qt Application found.") # get the QApplication instance, or crash if not set :path: A full path to a resource or file on system System (prefixed by `:/`) or generically (a path to a file on Toggle the stylesheet to use the desired path in the Qt resource You may then use the function as a slot to a Qt signal (warning: I primarily develop using C++, so there may be small errors in my code for the signal/slot mechanism). In response to a comment, the easiest way to adjust the stylesheet to use either the light or the dark stylesheet dynamically is to wrap it in a function. To use it in PyQt5, simply add the following lines to a project: import sysįrom PyQt5.QtCore import QFile, QTextStream ![]() This was (hard) forked from the excellent QDarkStylesheet, which I felt had theme issues in numerous areas, so I modified it extensively for my own needs and added a light theme. No, but you may use my fairly comprehensive stylesheets that should look excellent on most platforms (it's inspired by KDE's Breeze Theme, which is a dark theme that is quite elegant).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |