Using PyQT, how do you filter mousePressEvent for a QComboBox with a custom list

I have QComboBoxwith a custom list object.

Screenshot

The custom list object has a custom one mousePressEvent, so when the user clicks on one of the circles with +/- (tortuous), the list expands / collapses.

When I use a list with a combo box, when the user clicks on a twist, the list expands / collapses, but the selection changes and the list is hidden. How can I filter this so that when the user clicks on the twist, the selection does not change, and the list is not hidden.

Additional screenshots

All nodes are collapsed: All nodes collapsed.

Hidden List: Screenshot with the list hidden.

+3
2

QT eventFilter, "" QEvent.MouseButtonRelease. , , eventFilter, QEvent.MouseButtonRelease, node.

list :

def mousePressEvent (self, e):
    self.colapse_expand_click = False
    if <user clicked node>:
        colapse_expand_node()
        e.accept ()
        self.colapse_expand_click = True

mousePressEvent mouseReleaseEvent.

:

class RevisionSelectorWidget(QtGui.QComboBox):
    def __init__(self, parent = None):
        QtGui.QComboBox.__init__(self, parent)

        self.log_list = RevisionSelectorLogList(self)
        self.setView(self.log_list)
        self.log_list.installEventFilter(self)
        self.log_list.viewport().installEventFilter(self)

    def eventFilter(self, object, event):
        if event.type() == QtCore.QEvent.MouseButtonRelease:
            if self.log_list.colapse_expand_click:
                return True
        return False
+2

QComboBox hideEvent(QHideEvent) ( QWidget)

def hideEvent(self, event):
  if self.OkToHide():
    event.accept()
  else:
    event.ignore()

, , TreeView ?

(14 2009 .):

Qt, , , qt "activated(int index)", "hidePopup()".

, , - "activated(int index)" "highlighted(int index)" , "showPopup()", . / , Qt .

, !

+1

Source: https://habr.com/ru/post/1704087/


All Articles