I apologize in advance for the vague title but I would like to know if
there are any ways that I can try using to check if the signals/ events in
the parent is blocking the signals/events in the child widget, or vice
verse?
class QSubAction(QtGui.QAction):
def __init__(self, text="", parent=None):
super(QSubAction, self).__init__(text, parent)
self.setCheckable(True)
self.setChecked(True)
class QCustomMenu(QtGui.QMenu):
def __init__(self, title, parent=None):
super(QCustomMenu, self).__init__(title=str(title), parent=parent)
self.setup_menu()
self.parent = parent
def setup_menu(self):
self.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
def mousePressEvent(self, event):
print '\n--- qcustommenu mouse press event ---'
print '>>> parent : ', self.parent
print '>>> action : ', self.activeAction()
print '>>> actionAt : ', self.actionAt(event.pos())
'''
# If the option is toggled within the tool:
--- qcustommenu mouse press event ---
>>> parent : <tabbed_tool.ui.tabs.TabBar object at 0x7eff3bf2c128>
>>> action : None
--- qcustommenu mouse press event ---
>>> parent : <tabbed_tool.ui.tabs.TabBar object at 0x7eff3bf2c128>
>>> action : <PySide2.QtWidgets.QAction object at 0x7efdb0ccfb00>
# If the menu is in tear off mode:
--- qcustommenu mouse press event ---
>>> parent : <tabbed_tool.ui.tabs.TabBar object at 0x7eff3bf2c128>
>>> action : None
'''
action = self.activeAction()
if event.button() == QtCore.Qt.LeftButton:
if not isinstance(action, QSubAction) and action is not None:
action.trigger()
return
elif isinstance(action, QSubAction):
action.trigger()
return
return QtGui.QMenu.mousePressEvent(self, event)
class TabBar(QtGui.QTabBar):
def __init__(self, parent=None):
super(TabBar, self).__init__(parent)
...
...
def mousePressEvent(self, event):
self._rename_tab_allowed = False
if event.button() == QtCore.Qt.RightButton:
self.show_context_menu(event.pos(), index)
else:
super(TabBar, self).mousePressEvent(event)
def show_context_menu(self, position, index):
role = self.tabData(index)
self.context_menu = QCustomMenu(title="", parent=self)
self.context_menu.setTearOffEnabled(True)
In my above code example, I have a QMenu, in which its items (QAction) are
checkable.
The menu items can be toggle-able, however as soon as I tear off the QMenu,
the `activeAction` are no longer registering in the `mousePressEvent` nor
the menu items are toggle-able in this case.
Due to the complexity I have coded my tool, this is the snippet that is
seemingly causing the issues (pardon me for not being able to post a
working version)
Appreciate in advance if anyone could share of a workaround (if there are
any) to check for this 'blocking'
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/7db8f7ce-4f0e-4aca-bae7-c4068268bb9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.