I am occupying a QtableWidget
with PyQt 5
and I would like to know if there is a method that allows me to validate when I stopped editing a QtableWidgetItem
.
Thank you very much!
I am occupying a QtableWidget
with PyQt 5
and I would like to know if there is a method that allows me to validate when I stopped editing a QtableWidgetItem
.
Thank you very much!
It is not necessary to handle those events to validate a data, what you can do is use a delegate as I show below (this answer is published in for question the site in English so that it only allows you to write 2 hexadecimal digits, if you tell me that you want to validate I could give you an adequate answer for your specific question)
class HexDelegate(QItemDelegate):
def createEditor(self, parent, option, index):
w = QLineEdit(parent)
w.setInputMask("HH")
return w
class App(QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self, *args, **kwargs)
self.setLayout(QVBoxLayout())
# Create table
self.tableWidget = QTableWidget(self)
self.layout().addWidget(self.tableWidget)
self.tableWidget.setRowCount(4)
self.tableWidget.setColumnCount(2)
self.tableWidget.setItemDelegate(HexDelegate())
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())