PDA

View Full Version : How to know when a cell in a QTableWidget has been edited



Pepe
9th July 2007, 12:06
I'm trying to port a QTable to QTableWidget.

There's something that's killing me:

How can I know when a cell has just been edited by the user?

The signal itemChanged(QTableWidgetItem * item) is emited even when I change a cell with setItem, and that's not what I want.

guilugi
9th July 2007, 12:58
What do you mean by edited ?

-> Internal Value changed by double-clicking on the item ?

If that's the case, you may have to catch an itemDoubleClicked() signal, followed by an itemChanged()...

Pepe
10th July 2007, 02:35
I mean when the user has just finished of typing something on a cell.

I'm using currently the signal itemChanged() but that's emitted too when I change the text of a cell with setItem. So when I first add the data to the table, a function which makes some checks is called a lot of times unnecessary.

I even experimented with delegates. I almost got it. I created my own delegate, I wanted to send a signal from setModelData(), but for some reason it doesn't allow me to send a signal from that function :(

jpn
10th July 2007, 06:38
One cannot emit signals from a const function (http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-know-when-field-is-edited-within-qtableview-5024.html#4). Try this solution (http://www.qtcentre.org/forum/f-qt-programming-2/t-help-using-the-qtreewidget-persistent-editor-7810.html#9).

balazsbela
12th July 2007, 14:27
I once wrote a function that will tell me if a cell of QTableWidget is currently being edited by the user.



bool CQTableWidget::isBeingEdited()
{
if(this->state()==QAbstractItemView::EditingState)
return 1;
else return 0;
};


I needed to subclass QTableWidget though because state() is protected but you could use friend classes.
But this won't tell you which cell is being edited :(.
Hope it helps you.
Cheers.

tyranul
26th October 2014, 12:56
Hi! I know it's a little latte but for someone who have the same problem the solution is: when you invoke method setItem for QTableWidget you need to block signals and make changes with setItem afet that need to invoke one more time blockSignals with false argument and that's it.
Now the slot for itemChanged will work normal when you will edit data in table.