Frage

I have subclassed QTableWidget to add some functionality. I have used the myQTableWidgetSubclass->setRowCount(10); method as well.

The problem is that the table is not editable. The goal is to allow the user to edit row by row, e.g. first the first row, and when that is ready (i.e. user fills the necessary data in), then the second, etc.

I would need a similar functionality to "MS access table"

War es hilfreich?

Lösung

Theoretically, this is very simple, but people will not write code for you from scratch.

1) You will need to use void QTableWidgetItem::setFlags(Qt::ItemFlags flags) to make items editable and non-editable. You can use this method for each item as you wish.

See the following enumeration value description from the documentation of Qt::ItemFlags:

Qt::ItemIsEditable 2 It can be edited.

2) Once that is done, you need to connect your custom slot to the corresponding signal of an item that has just been edited. Your slot would then rearrange the editable feature of the cells respectively.

Here are the relevant signals that may be of interest for you:

* void QTableWidget::cellChanged(int row, int column) [signal]
* void QTableWidget::currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) [signal]
* void QTableWidget::currentItemChanged(QTableWidgetItem * current, QTableWidgetItem * previous) [signal]
* void QTableWidget::itemChanged(QTableWidgetItem * item) [signal]

Then, you will need something like this:

connect(myQTableWidgetSubclass, SIGNAL(selectedSignalFromAbove), this, SLOT(mySlotInTheClass));

// ...

void MyClass::mySlotInTheClass(...)
{
    // ...
    myTableWidgetItemX.setFlags(...);
    // ...
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top