i perform input validation on customized qtablewidget has setitemdelegate subclass of qstyleditemdelegate. input validation works , error message pops correctly, focus moves on next cell selection (ie: if pressed tab perform input validation, print msg if bad input, , move focus adjacent cell). focus remain on first cell until input correct.
perhaps if edit tab traversal manually control traversal in table (ie: check if input valid traverse tab) achieve input validation; however, unaware of method modify table's (qtablewidget) default tab traversal (described in detailed description of superclass qabstractitemview).
below relevant code:
class theeditor(qlineedit): # signal tell delegate when have finished editing editingfinished = signal() def __init__(self, parent=none): # initialize editor object super(theeditor, self).__init__(parent) self.setautofillbackground(true) self.setvalidator(qintvalidator(0,999999999, self)) def focusoutevent(self, event): # once focus lost, tell delegate we're done editing self.editingfinished.emit() class editdelegate(qstyleditemdelegate): def __init__(self, parent=none): super(editdelegate, self).__init__(parent) def createeditor(self, parent, option, index): # creates , returns custom editor object use edit cell result = index.column() if result==0: editor = theeditor(parent) editor.editingfinished.connect(self.checkinput) return editor else: return qstyleditemdelegate.createeditor(self, parent, option, index) def errormessage(self, error_message): newqwidget = qwidget() qtgui.qmessagebox.critical(newqwidget, "invalid entry", error_message, qtgui.qmessagebox.retry) def checkinput(self): # ... code here validation if result == expected: # input! self.commitdata.emit(editor) self.closeeditor.emit(editor, qabstractitemdelegate.editnextitem) return true else: # bad input! self.errormessage("invalid!") self.closeeditor.emit(editor, qabstractitemdelegate.nohint) return true
does have suggestions achieve input validation? found similar question here wasn't able implement worked.
maybe checkinput
can return false
in case of bad input. use information define current index of model using setcurrentindex(index)
.
Comments
Post a Comment