qt - Why does editing in QTreeView get initiated by other triggers than the one I have enabled? -
i have enabled selectedclicked edit trigger in qtreeview, item editing (via edit method) still getting triggered other reasons (e.g., currentchanged
). why other triggers active?
see program below example, when clicking tree items should see editing gets triggered several different reasons:
from pyqt5.qtcore import * pyqt5.qtwidgets import * pyqt5.qtgui import * class treeview(qtreeview): def __init__(self): super().__init__() self.setedittriggers(self.selectedclicked) self.__model = qstandarditemmodel() self.__model.appendrow([qstandarditem('item 1')]) self.__model.appendrow([qstandarditem('item 2')]) self.setmodel(self.__model) def edit(self, index, trigger, event): print('edit index {},{}, trigger: {}'.format(index.row(), index.column(), trigger)) return false app = qapplication([]) w = treeview() w.show() app.exec_()
edit called, whatever edittrigger use. however, depending on trigger specify, edit slot job create or not editor, , return true or false (see qt documentation). in code, edit nothing (and item don't edited since no editor created). try calling super().edit(self, index, trigger, event)
.
def edit(self, index, trigger, event): res = super().edit(index, trigger, event) print('edit {},{}, trigger: {}, accepted: {}'.format(index.row(), index.column(), trigger, res)) return res
Comments
Post a Comment