Exemplo n.º 1
0
 def keyPressEvent(self, ev):
     if handle_enter_press(self, ev, self.start_view_animation, False):
         return
     k = ev.key()
     if ev.modifiers() & Qt.KeyboardModifier.ShiftModifier and k in (Qt.Key.Key_Left, Qt.Key.Key_Right, Qt.Key.Key_Up, Qt.Key.Key_Down):
         ci = self.currentIndex()
         if not ci.isValid():
             return
         c = ci.row()
         ncols = self.number_of_columns() or 1
         delta = {Qt.Key.Key_Left: -1, Qt.Key.Key_Right: 1, Qt.Key.Key_Up: -ncols, Qt.Key.Key_Down: ncols}[k]
         n = max(0, min(c + delta, self.model().rowCount(None) - 1))
         if n == c:
             return
         sm = self.selectionModel()
         rows = {i.row() for i in sm.selectedIndexes()}
         if rows:
             mi, ma = min(rows), max(rows)
             end = mi if c == ma else ma if c == mi else c
         else:
             end = c
         top = self.model().index(min(n, end), 0)
         bottom = self.model().index(max(n, end), 0)
         sm.select(QItemSelection(top, bottom), QItemSelectionModel.SelectionFlag.ClearAndSelect)
         sm.setCurrentIndex(self.model().index(n, 0), QItemSelectionModel.SelectionFlag.NoUpdate)
     else:
         return QListView.keyPressEvent(self, ev)
Exemplo n.º 2
0
 def keyPressEvent(self, ev):
     if ev.key() in (Qt.Key.Key_Enter, Qt.Key.Key_Return):
         self.chosen.emit()
         ev.accept()
         return
     return QListView.keyPressEvent(self, ev)