diff --git a/example/widgets.py b/example/widgets.py index 747d5c7..89cac0a 100644 --- a/example/widgets.py +++ b/example/widgets.py @@ -115,7 +115,7 @@ if args.pyqt6: ReadOnly = QtCore.QFile.OpenModeFlag.ReadOnly Text = QtCore.QFile.OpenModeFlag.Text East = QtWidgets.QTabWidget.TabPosition.East - SP_DialogResetButton = QtWidgets.QStyle.StandardPixmap.SP_DialogResetButton + SP_DockWidgetCloseButton = QtWidgets.QStyle.StandardPixmap.SP_DockWidgetCloseButton else: QAction = QtWidgets.QAction Horizontal = QtCore.Qt.Horizontal @@ -137,7 +137,7 @@ else: ReadOnly = QtCore.QFile.ReadOnly Text = QtCore.QFile.Text East = QtWidgets.QTabWidget.East - SP_DialogResetButton = QtWidgets.QStyle.SP_DialogResetButton + SP_DockWidgetCloseButton = QtWidgets.QStyle.SP_DockWidgetCloseButton # Need to fix an issue on Wayland on Linux: # conda-forge does not support Wayland, for who knows what reason. @@ -147,6 +147,14 @@ if sys.platform.lower().startswith('linux') and 'CONDA_PREFIX' in os.environ: if args.use_x11: os.environ['XDG_SESSION_TYPE'] = 'x11' +def close_icon(widget): + '''Get the close icon depending on the stylesheet.''' + + if args.stylesheet == 'native': + return widget.style().standardIcon(SP_DockWidgetCloseButton) + return QtGui.QIcon(f'{resource_format}close.svg') + + class Ui: '''Main class for the user interface.''' @@ -366,8 +374,7 @@ class Ui: self.horizontalLayout.addWidget(self.bt_menu_button_popup) self.bt_auto_raise = QtWidgets.QToolButton(self.centralwidget) self.bt_auto_raise.setAutoRaise(True) - auto_raise_icon = self.bt_auto_raise.style().standardIcon(SP_DialogResetButton) - self.bt_auto_raise.setIcon(auto_raise_icon) + self.bt_auto_raise.setIcon(close_icon(self.bt_auto_raise)) self.bt_auto_raise.setObjectName('bt_auto_raise') self.horizontalLayout.addWidget(self.bt_auto_raise) self.line_2 = QtWidgets.QFrame(self.centralwidget) diff --git a/test/ui.py b/test/ui.py index 4b1e0bc..73ba80e 100644 --- a/test/ui.py +++ b/test/ui.py @@ -471,6 +471,13 @@ def execute(obj): else: return obj.exec_() +def close_icon(widget): + '''Get the close icon depending on the stylesheet.''' + + if args.stylesheet == 'native': + return widget.style().standardIcon(SP_DockWidgetCloseButton) + return QtGui.QIcon(f'{resource_format}close.svg') + def test_progressbar_horizontal(widget, *_): child = [] bar1 = QtWidgets.QProgressBar(widget) @@ -561,7 +568,7 @@ def test_menu(widget, window, font, width, *_): action3 = QAction('&Action 6', window) action3.setCheckable(True) menu.addAction(action3) - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(menu) menu.addAction(QAction(icon, '&Action 7', window)) menu.addAction(QAction(icon, '&Action 8', window)) submenu.addAction(QAction(icon, '&Action 9', window)) @@ -723,7 +730,7 @@ def test_list(widget, *_): item = QtWidgets.QListWidgetItem(f'Item {index + 1}') item.setTextAlignment(random.choice(alignments)) child.addItem(item) - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(child) for index in range(10): item = QtWidgets.QListWidgetItem(icon, f'Item {index + 1}') item.setTextAlignment(random.choice(alignments)) @@ -757,7 +764,7 @@ def test_toolbar(_, window, *__): toolbar1.addSeparator() toolbar1.addAction('&Action 3') toolbar1.addAction('&Action 3 Really Long Name') - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(toolbar1) toolbar1.addAction(icon, '&Action 4') window.addToolBar(TopToolBarArea, toolbar1) @@ -768,7 +775,7 @@ def test_toolbar(_, window, *__): toolbar2.addSeparator() toolbar2.addAction('&Action 3') toolbar2.addAction('&Action 3 Really Long Name') - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(toolbar2) toolbar2.addAction(icon, '&Action 4') window.addToolBar(LeftToolBarArea, toolbar2) @@ -816,7 +823,7 @@ def test_toolbutton(widget, window, *_): child[5].setArrowType(RightArrow) child[6].setArrowType(UpArrow) child[7].setArrowType(DownArrow) - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(widget) child[8].setIcon(icon) return child, layout_type @@ -828,7 +835,7 @@ def test_pushbutton(widget, *_): child.append(abstract_button(widget_type, widget, 'Button 1', checked=True)) child.append(abstract_button(widget_type, widget, 'Button 2', enabled=False)) child.append(abstract_button(widget_type, widget, 'Button 3', checkable=False)) - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(widget) child.append(abstract_button(widget_type, widget, icon, 'Button 4', checkable=False)) return child, layout_type @@ -1079,7 +1086,7 @@ def test_disabled_menu(widget, window, font, width, *_): action3 = QAction('&Action 6', window) action3.setCheckable(True) menu.addAction(action3) - icon = menu.style().standardIcon(SP_DockWidgetCloseButton) + icon = close_icon(menu) menu.addAction(QAction(icon, '&Action 7', window)) menu.addAction(QAction(icon, '&Action 8', window)) menu.actions()[2].setEnabled(False)