From 912ad165d52df7825f2ca573a8b7c5117b99d090 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 16 Nov 2021 19:15:36 +0100 Subject: [PATCH] added new button with menu --- openpype/style/style.css | 19 ++++++++++++++ openpype/tools/sceneinventory/widgets.py | 33 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/openpype/style/style.css b/openpype/style/style.css index 89458fd117..2b81905016 100644 --- a/openpype/style/style.css +++ b/openpype/style/style.css @@ -771,6 +771,25 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { border: 1px solid #ff0000; } +/* Scene Inventory*/ +#ButtonWithMenu { + padding-right: 16px; + border: 1px solid #4A4949; + border-radius: 2px; +} +#ButtonWithMenu::menu-button { + border: 1px solid #4A4949; + width: 12px; + border-top-left-radius: 0px; + border-top-right-radius: 2px; + border-bottom-right-radius: 2px; + border-bottom-left-radius: 0px; +} + +#ButtonWithMenu[state="1"], #ButtonWithMenu[state="1"]::menu-button, #ButtonWithMenu[state="1"]::menu-button:hover { + border-color: green; +} + /* Python console interpreter */ #PythonInterpreterOutput, #PythonCodeEditor { font-family: "Roboto Mono"; diff --git a/openpype/tools/sceneinventory/widgets.py b/openpype/tools/sceneinventory/widgets.py index 6bb74d2d1b..587f443b82 100644 --- a/openpype/tools/sceneinventory/widgets.py +++ b/openpype/tools/sceneinventory/widgets.py @@ -1,6 +1,39 @@ from Qt import QtWidgets, QtCore +class ButtonWithMenu(QtWidgets.QToolButton): + def __init__(self, parent=None): + super(ButtonWithMenu, self).__init__(parent) + + self.setObjectName("ButtonWithMenu") + + self.setPopupMode(self.MenuButtonPopup) + menu = QtWidgets.QMenu(self) + + self.setMenu(menu) + + self._menu = menu + self._actions = [] + + def menu(self): + return self._menu + + def clear_actions(self): + if self._menu is not None: + self._menu.clear() + self._actions = [] + + def add_action(self, action): + self._actions.append(action) + self._menu.addAction(action) + + def _on_action_trigger(self): + action = self.sender() + if action not in self._actions: + return + action.trigger() + + class SearchComboBox(QtWidgets.QComboBox): """Searchable ComboBox with empty placeholder value as first value"""