Unsolved TableWidget cell highlights sometimes and other times doesn't. Two cell widget types.
-
class TranslationEditor(QMainWindow, Ui_TranslationEditor): def __init__(self): super().__init__() super().__init__() self.setupUi(self) self.addRow() def returnPressed(self): self.addRow() self.transTable.cellWidget(self.transTable.rowCount() - 1, 0).setFocus() def addRow(self): row_count = self.transTable.rowCount() byte_seq_line = self.createLineEdit() byte_seq_line.setValidator(HexStringValidator()) byte_seq_line.returnPressed.connect(self.returnPressed) loc_widget = NibbleLocationWidget() trans_line = self.createLineEdit() trans_line.returnPressed.connect(self.returnPressed) comment_line = self.createLineEdit() comment_line.returnPressed.connect(self.returnPressed) self.setTabOrders([byte_seq_line, loc_widget, trans_line, comment_line]) self.transTable.setRowCount(row_count + 1) self.transTable.setCellWidget(row_count, 0, byte_seq_line) self.transTable.setCellWidget(row_count, 1, loc_widget) self.transTable.setCellWidget(row_count, 3, comment_line) def setTabOrders(self, widgets): for k in range(len(widgets) - 1): self.setTabOrder(widgets[k], widgets[k+1]) @staticmethod def createLineEdit(): line_edit = QLineEdit() line_edit.setFrame(False) return line_edit
Result:
Opening translation editor:
Pressing tab key once:
Pressing tab key again:
And one last tab key press:
Obviously, I can't release a professional app if it's doing this. Any idea how to get the field highlighting to consistently be like the 1st and 4th cells when entered?
Each cell except for nibble location has a QLineEdit (see code).
-
I'll try taking out the spinbox and just using a validated lineedit. Should work.
-
Or just do the right thing and use a delegate (QStyledItemDelegate subclass) for the columns instead of setCellWidget