src/eric7/EricWidgets/EricToolButton.py

branch
eric7
changeset 9643
10839ab864e0
parent 9473
3f23dbf37dbe
child 9653
e67609152c5e
--- a/src/eric7/EricWidgets/EricToolButton.py	Fri Dec 23 10:58:36 2022 +0100
+++ b/src/eric7/EricWidgets/EricToolButton.py	Fri Dec 23 11:35:54 2022 +0100
@@ -104,13 +104,19 @@
         @param menu reference to the tool button menu
         @type QMenu
         """
-        if menu is not None:
+        if menu is None:
+            # show the default tool button context menu
+            self.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu)
+        else:
             if self.__menu:
                 self.__menu.aboutToHide.disconnect(self.__menuAboutToHide)
 
             self.__menu = menu
             self.__menu.aboutToHide.connect(self.__menuAboutToHide)
 
+            # prevent showing the context menu and the tool button menu
+            self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
+
     def showMenuInside(self):
         """
         Public method to check, if the menu edge shall be aligned with
@@ -261,19 +267,6 @@
         if evt.buttons() == Qt.MouseButton.LeftButton:
             self.doubleClicked.emit()
 
-    def contextMenuEvent(self, evt):
-        """
-        Protected method to handle context menu events.
-
-        @param evt reference to the context menu event
-        @type QContextMenuEvent
-        """
-        # block to prevent showing the context menu and the tool button menu
-        if self.__menu is not None:
-            return
-
-        super().contextMenuEvent(evt)
-
     ##################################################################
     ## Methods to handle the tool button badge
     ##################################################################

eric ide

mercurial