def keyPressEvent(self, event): key = int(event.key()) mods = int(event.modifiers()) #pqMsgs.printKeyEvent(event) if (key == Qt.Key_C) and (mods & Qt.ControlModifier) : event.accept() # PyQt4's implementation of QTableView::selectedIndexes() does # not return a QList but rather a Python list of indices. lix = self.selectedIndexes() if len(lix) : # non-zero selection ans = QString() for ix in lix : ans.append( self.model().data(ix, Qt.DisplayRole).toString() ) ans.append(u' ') ans.chop(1) # drop final space QApplication.clipboard().setText(ans) elif (0 == key & 0x01000000) and \ ( (mods == Qt.NoModifier) or (mods == Qt.ShiftModifier) ) and \ ( 0 == self.horizontalHeader().sortIndicatorSection()) and \ ( Qt.AscendingOrder == self.horizontalHeader().sortIndicatorOrder() ): # An ordinary data key with or without shift, and the table # is sorted on column 0, the words, and sorted ascending. event.accept() sortProxy = self.panelRef.proxy rc = self.panelRef.caseSwitch.isChecked() qc = QChar(key) if rc and (mods == Qt.NoModifier) : qc = qc.toLower() hi = sortProxy.rowCount() lo = 0 while (lo < hi) : mid = (lo + hi) // 2 cc = sortProxy.data(sortProxy.index(mid,0)).toString().at(0) if not rc : cc = cc.toUpper() if qc > cc : lo = mid + 1 else : hi = mid self.scrollTo(sortProxy.index(lo,0)) if not event.isAccepted() : # if we didn't handle it, pass it up super(myTableView, self).keyPressEvent(event)