Cool_Coder
Cool_Coder

Reputation: 5083

Undo for individual cells of QTableWidget in Qt?

I have a QTableWidget in my Main Window class. I am unable to find a functionality which will undo the text change for the specified cell. What I want to do is:

    void myCellUndoFunc(int row, int col)
    {
        table->item(row, col)->undo(); //table is my QTableWidget
    }

The problem is that there is no such undo(). So my question is, can there be a workaround for this problem using maybe some foo-doo combination of SIGNAL's & SLOT's?

Thanks!

PS: Please do not suggest to use Model/View framework because I have used QTableWidget extensively in my application. Sorry for the same.

Upvotes: 0

Views: 1597

Answers (1)

Trashed
Trashed

Reputation: 146

Maybe you should use the

void QTableWidgetItem::setData ( int role, const QVariant & value ) [virtual]

using the Qt::UserRole you are able to specify the last value. In your method u can access the previously set value with the data()-Method. The only thing you have to do is always keep the old value up-to-date.

Before you set the new value of the QTableWidgetItem

tw->setData(Qt::UserRole, tw->text())

and on undo u could than retrieve the data with

tw->setText(tw->data(Qt::UserRole).toString())

where "tw" is the current QTableWidgetItem using the contextmenu-event, the clicked-event or whatever u want. You could also subclass the QTableWidgetItem and handle this whole thing internally in your class, creating an undo()-method, storing the old value, etc.

Upvotes: 1

Related Questions