![]() setProperty ( "type", "sidebar" ) Widget You can use setProperty() of the widget object to apply a modern style.įor example, if you set the QToolbar type property to sidebar, the style for the sidebar will be applied. This module provides several custom properties. Input the following command in a terminal to check common widgets. load_stylesheet ( "light" )) Check common widgets argv ) main_win = QMainWindow () push_button = QPushButton ( "PyQtDarkTheme!!" ) main_win. Usage import sys import qdarktheme from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton app = QApplication ( sys. Color and style balanced from the Dark theme for easy viewing in daylight. This python module applies a theme to a Qt applications(PySide6, PyQt6, PyQt5 and PySide2) using a qt stylesheets system. tThemeName(self.Dark theme for PySide, PyQt and Qt Designer. I haven't yet found a way to define icons from the theme directly via QtDesigner but here is the modified code and it works, icons are directly updated when the user clicks on switch_mode (and now I have my ugly dark mode window. When adding files to the resources file the default prefix is / but it seems Qt searches for icons in a theme (QIcon.themeSearchPaths()) from :/icons (explained here : ). I think I understood why until now I could not set my icons with fromTheme. I then added the already existing directories to my resources.qrc file (right click then "Add Existing directory" where I select the index.theme files + the icons of each theme). The files are in 2 separate directories (named "light" and "dark") each containing a "test" subdirectory that contains the png icons. (This link seems to be a good start point to understand. Here the light index.theme file (very simplified for the test, and just change the name for the dark theme): This allowing to check if initial resource paths are right, I can see the open_eye and close_eye icons on QPushbuttons.Īs suggested, I solved the problem by generating theme files and calling the tThemeName("selected_theme_name") method to actually update the paths of the icons used in the application. Print("i name ", i_name) **# print empty string**Įx_selectors = ] If not ic.isNull() : # Check if object icon is not Null Obj.setStyleSheet(obj.styleSheet()+self.styles) # Change main window children background color ![]() ![]() # Get all objects in main window if is instance of QWidgetĬhild for child in self.centralWidget().children() # Test access icon name **-> Get icon object id but nothing for name** PS : I have a style file that manages the appearance of the interface but for simplicity here I have just applied a white or black background colour depending on the theme. Here is an example of what I am trying to do. The problem I'm having is that I can't access the name of my icon, so I can't redefine the new resource path. My idea was the following: when the user clicks on the "switch_mode" button, I browse all the QWidget instances of the window and if an icon has been assigned to them, I retrieve the path/name of the icon to redefine it with the new theme. ![]() I manage the path of the icons by calling the select function on the QFileSelector instance after setting the extra selector on the currently selected theme. My strategy was quite simple : my icons are managed via the resources.qrc file under the prefixes "+theme_light" or "+theme_dark". Thanks in advance for your advice and help. ![]() The problem is that I can't access to buttons icon name, and so I can't redefine the new resource path according to light/dark mode. I am developing a GUI based on PyQt5 (I'm using Qt creator 8.0.0 based on Qt6.3) and I want to update the icons when the user switches the application to "dark" or "light" mode (ie, icon is black png for light mode and white png for dark mode). ![]()
0 Comments
Leave a Reply. |