python 3.x - After subclassing QTableView an using keyPressEvent ive lost use of arrow keys. How can I easily use them to navigate while keeping the custom signal? -
so title says, after subclassing qtableview able use return/enter key select rows view, i've lost ability use , down arrows navigate view . i'm able use keys in subclass (as can print when press or down arrow) having problems making selected row move , down them. best option create custom signals , down , connect them own functions force move selected row?
this subclass:
class customqtableview(qtwidgets.qtableview): signal = qtcore.pyqtsignal() def __init__(self, *args, **kwargs): qtwidgets.qtableview.__init__(self, *args, **kwargs) def keypressevent(self, event): if event.key() == qtcore.qt.key_return: self.signal.emit() elif event.key() == qtcore.qt.key_up: print("up") elif event.key() == qtcore.qt.key_down: print("down") else: pass
this solved self quite nicely. ill add code here in case else ever face same problem
custom widget (qtableview)
class customqtableview(qtwidgets.qtableview): signal = qtcore.pyqtsignal() signal_up = qtcore.pyqtsignal() signal_down = qtcore.pyqtsignal() def __init__(self, *args, **kwargs): qtwidgets.qtableview.__init__(self, *args, **kwargs) self.setselectionmode(qtwidgets.qabstractitemview.singleselection) self.scrollhint(qtwidgets.qabstractitemview.ensurevisible) def keypressevent(self, event): if event.key() == qtcore.qt.key_return: self.signal.emit() elif event.key() == qtcore.qt.key_up: self.signal_up.emit() elif event.key() == qtcore.qt.key_down: self.signal_down.emit() else: pass
and function use move selected row arrow keys:
def arrowkey(self,num): try: selection_model = self.ui.vt_produkt_treff.selectionmodel() indexes = selection_model.selectedindexes() muh = indexes[0].row() self.ui.vt_produkt_treff.clearselection() self.ui.vt_produkt_treff.selectrow(muh+ num) except unboundlocalerror: pass
Comments
Post a Comment