storm_to
storm_to

Reputation: 1575

QTableWidget how to have a cell selected for editing from code and/or with single click

Two part question: I have a 10x10 QTableWidget with QTableWidgetItem in each cell. For some reason, clicking on a cell is not sufficient to edit it, I need to double-click the cell to enter it.

  1. Is there a way to change this behavior to single click

  2. Is there a way to have 2nd cell in 1st row selected and ready for editing by default when window is created?

Upvotes: 2

Views: 4830

Answers (2)

ekhumoro
ekhumoro

Reputation: 120578

You can modify the editing behaviour in various ways with setEditTriggers.

For single-click, try:

table.setEditTriggers(QAbstractItemView.CurrentChanged)

The current edited cell can be set with editItem:

table.editItem(table.item(0, 1))

To select a cell without editing it, use setCurrentCell:

table.setCurrentCell(0, 1)

Upvotes: 3

Vicky T
Vicky T

Reputation: 1633

You can also use setCurrentCell.

table.setCurrentCell(0,1)

QTableWidget.setCurrentCell (self, int row, int column)

Upvotes: 2

Related Questions