UN-GCPDS / qt-material

Material inspired stylesheet for PySide2, PySide6, PyQt5 and PyQt6
https://qt-material.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
2.22k stars 240 forks source link

QIcons are squashed starting with version 2.9 #92

Open steinmig opened 1 year ago

steinmig commented 1 year ago

Running on redhat8 with PySide2==5.15.2.1

I have the issue that icons that I add by adding a QAction to a QToolBar, that the resulting icons are squashed, when I update from 2.8 to 2.9 (see Screenshots)

image

image

In this case, they are custom icons, but I also have the same issue, when I add PySide default icons, such as QStyle.SP_DialogSaveButton.

The issue arises when I have a widget that inherits from QToolBar, but is not added to another widget via setMenuBar, but just as any other widget. If it is a proper toolbar, the icons are displayed normally.

Code example for the toolbar:

class BaseToolBar(QToolBar):
    """
    Simplifying some interaction with the QToolBar
    """

    def __init__(self, parent: Optional[QObject] = None):
        super(BaseToolBar, self).__init__(parent=parent)

    def shortened_add_action(self, icon, text: str, shortcut: str, function: Callable) -> QAction:
        if shortcut:
            q_shortcut = QKeySequence(shortcut)
            description_string = f'{text} ({q_shortcut.toString()})'
        else:
            description_string = text
        if isinstance(icon, str):
            icon = QIcon(os.path.join(resource_path(), 'icons', icon))
        else:
            icon = self.style().standardIcon(icon)
        action = self.addAction(
            icon,
            self.tr(description_string),  # type: ignore[arg-type]
        )   
        if shortcut:
            action.setShortcut(q_shortcut)
        action.triggered.connect(function)  # pylint: disable=no-member

        return action

class ToolBarWithSaveLoad(BaseToolBar):

    def __init__(self, save_call: Callable, load_call: Callable, parent: Optional[QObject] = None):
        super().__init__(parent=parent)
        self.shortened_add_action(
            QStyle.SP_DialogSaveButton, "Save Setup", "Ctrl+S", save_call
        )
        self.shortened_add_action(
            QStyle.SP_DialogOpenButton, "Load Setup", "Ctrl+O", load_call
        )

The toolbar is then added like:

toolbar = ToolBarWithSaveLoad(save_fun, load_fun)
layout = QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(other_widget)
self.setLayout(layout)

Due to layout reasons, I cannot use setMenuBar every time. Any pointers for possible reasons or fixes?