0

I have a QTableWidget with data.

At runtime i am adding row and inserting default data (header names) in cells.

User will be filling the data by removing default data.

So i want to make it easy for end user. So thought of selecting the first cell in currently added row. So that user can directly add data and move to next cell with Tab.

Have a look at my snapshot (Row 386 is added at runtime).

The last row is what i have added dynamically, and the row is editable.

enter image description here

I want it to be like this below image by selecting the first cell of the added row

enter image description here

Rao
  • 2,902
  • 14
  • 52
  • 70

1 Answers1

0

From Qt Documentation:

void QTableWidget::editItem ( QTableWidgetItem * item )

Starts editing the item if it is editable.

so, in Python it would be something like this:

def addNewRow(self):
    row =  self.tableWidget.rowCount()
    #....add data to row cells and set flags to items here...
    #next line goes at the end of method - after row is populated
    self.tableWidget.editItem(self.tableWidget.item(row, 0))

you must set this flags to items: setFlags(Qt.ItemIsEditable | Qt.ItemIsSelectable | Qt.ItemIsEnabled);

Aleksandar
  • 3,541
  • 4
  • 34
  • 57