Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QIcons are squashed starting with version 2.9 #92

Open
steinmig opened this issue May 2, 2023 · 0 comments
Open

QIcons are squashed starting with version 2.9 #92

steinmig opened this issue May 2, 2023 · 0 comments

Comments

@steinmig
Copy link

steinmig commented May 2, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant