0

I have a QTableview and QItem delegate set to it, the editor is a QCombobox which I reimplemented, because I wanted to modify its keyPressEvent. because if I press down key when the qcombobox editor is open it selects the next row in the editor, but I want the next row in the tableView should be selected, don't want the rows in the comboBox should change.

So here is my event code for the QComboBox:

def keyPressEvent(self, event):
    key = event.key()
    if key == Qt.Key_Down:
        self.close()
    else:
        QComboBox.keyPressEvent(self, event)

however when I press down key, the item in the tableView to the right of the comboBox is being selected, why does closing the editor result in any selection change at all? And how could I control that?

Ankur Ankan
  • 2,953
  • 2
  • 23
  • 38
JoeMicro
  • 183
  • 1
  • 2
  • 13

1 Answers1

0

So i don't know why it behaves that way, but i modified my code to control its behavior as follows:

def keyPressEvent(self, event):
    key = event.key()
    if self.widget_parent:
        if key == Qt.Key_Down:
            index = self.widget_parent.currentIndex()
            self.close()
            index = self.widget_parent.model().index(index.row() + 1, index.column())
            self.widget_parent.setFocus()
            self.widget_parent.setCurrentIndex(index)
            self.widget_parent.edit(index)    
    else:
        QComboBox.keyPressEvent(self, event)

basically changing the currentIndex of the tabelView from inside the editor event.

JoeMicro
  • 183
  • 1
  • 2
  • 13