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

[bugfix] RibbonGallery.addButton should return a tuple of two buttons #102

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions include/qtribbon/gallery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QSize>
#include <QToolButton>
#include <QVBoxLayout>
#include <tuple>

#include "menu.hpp"
#include "separator.hpp"
Expand Down Expand Up @@ -225,9 +226,11 @@ class RibbonGallery : public QFrame {

void setPopupHideOnClick(bool popupHideOnClick) { _popupHideOnClick = popupHideOnClick; }

RibbonToolButton *addButton(const QString &text = "", const QIcon &icon = QIcon(),
const QKeySequence &shortcut = QKeySequence(), const QString &tooltip = "",
const QString &statusTip = "", bool checkable = false) {
std::tuple<RibbonToolButton *, RibbonToolButton *> addButton(const QString &text = "", const QIcon &icon = QIcon(),
const QKeySequence &shortcut = QKeySequence(),
const QString &tooltip = "",
const QString &statusTip = "",
bool checkable = false) {
auto *button = new RibbonToolButton(this);
auto *popupButton = new RibbonToolButton(_popupWidget);
if (!text.isEmpty()) {
Expand Down Expand Up @@ -270,12 +273,14 @@ class RibbonGallery : public QFrame {
}
_addWidget(button);
_addPopupWidget(popupButton);
return button;
return std::make_tuple(button, popupButton);
}

RibbonToolButton *addToggleButton(const QString &text = "", const QIcon &icon = QIcon(),
const QKeySequence &shortcut = QKeySequence(), const QString &tooltip = "",
const QString &statusTip = "") {
std::tuple<RibbonToolButton *, RibbonToolButton *> addToggleButton(const QString &text = "",
const QIcon &icon = QIcon(),
const QKeySequence &shortcut = QKeySequence(),
const QString &tooltip = "",
const QString &statusTip = "") {
return addButton(text, icon, shortcut, tooltip, statusTip, true);
}
};
Expand Down
13 changes: 6 additions & 7 deletions pyqtribbon/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def addButton(
tooltip=None,
statusTip=None,
checkable=False,
) -> RibbonToolButton:
) -> typing.Tuple[RibbonToolButton, RibbonToolButton]:
"""Add a button to the gallery

:param text: text of the button
Expand All @@ -250,7 +250,7 @@ def addButton(
:param tooltip: tooltip of the button
:param statusTip: status tip of the button
:param checkable: checkable flag of the button.
:return: the button added
:return: the button and the popup button added
"""
button = RibbonToolButton(self)
popupButton = RibbonToolButton(self._popupWidget)
Expand Down Expand Up @@ -290,7 +290,7 @@ def addButton(
popupButton.setToolButtonStyle(QtCore.Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
self._addWidget(button) # noqa
self._addPopupWidget(popupButton) # noqa
return button
return button, popupButton

def addToggleButton(
self,
Expand All @@ -300,7 +300,7 @@ def addToggleButton(
shortcut=None,
tooltip=None,
statusTip=None,
) -> RibbonToolButton:
) -> typing.Tuple[RibbonToolButton, RibbonToolButton]:
"""Add a toggle button to the gallery

:param text: text of the button
Expand All @@ -309,7 +309,6 @@ def addToggleButton(
:param shortcut: shortcut of the button
:param tooltip: tooltip of the button
:param statusTip: status tip of the button.
:return: the button added
:return: the button and the popup button added
"""
button = self.addButton(text, icon, slot, shortcut, tooltip, statusTip, True)
return button
return self.addButton(text, icon, slot, shortcut, tooltip, statusTip, True)
Loading