Catch mouse button pressed signal from qComboBox popup menu

后端 未结 1 1886
谎友^
谎友^ 2020-12-06 19:22

I have made multi-select QComboBox. Items are checkable (every item have check box and text value). CheckBox is checked only when user click on it. What I want

相关标签:
1条回答
  • 2020-12-06 20:23

    You need to connect a handler to the pressed signal of the combo's view:

        self.ui.comboBox.view().pressed.connect(self.handleItemPressed)
        ...
    
        def handleItemPressed(self, index):
            item = self.ui.comboBox.model().itemFromIndex(index)
            if item.checkState() == QtCore.Qt.Checked:
                item.setCheckState(QtCore.Qt.Unchecked)
            else:
                item.setCheckState(QtCore.Qt.Checked)
    
    0 讨论(0)
提交回复
热议问题