On Tue, Apr 16, 2019 at 8:58 AM kiteh <kiteh.0...@gmail.com> wrote: > 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' >
The idea of checking for blocked signals/events is probably not the issue here. I don't have in-depth knowledge of the underlying tear-off menu logic, but a little bit of searching on it gives a good idea of what could be going on. The docs for QMenu.tearOffEnabled <https://doc.qt.io/qt-5/qmenu.html#tearOffEnabled-prop> describe that a tear off menu is an internal copy of the original menu with all the same action instances added. So that right there lead me to believe it is the cause of your issue. When I searched a bit more, I saw various posts confirming the same thing. Then I checked the source: https://github.com/qt/qtbase/blob/5.12/src/widgets/widgets/qmenu.cpp#L89 You can see that this uses an internal QTornOffMenu which subclasses QMenu. The constructor takes your original custom menu and copies the actions into it. This means that your custom menu event handling is no longer integrated with this tear-off menu, since the tear-off is not your actual menu. I don't have a concrete suggestion for how to go about applying your same custom class logic to the tear off menu. Some random ideas could be trying to focus all your custom logic into the actions and not the menu, since the actions get copied to a new menu. Or you would have to implement your own tear off so that you can control the new custom menu. Or you would have to detect when the tear off menu is created as a sibling to your custom QMenu (it is parented to the parent of your menu). > -- > 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 python_inside_maya+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/7db8f7ce-4f0e-4aca-bae7-c4068268bb9f%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/7db8f7ce-4f0e-4aca-bae7-c4068268bb9f%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0g%2BKcCMXZH47XJr%3DNzhy9HrkpwqU7Q6EDeG0%3Dq5tcZ8w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.