View Full Version : How to know when a cell in a QTableWidget has been edited
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, 13: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, 03: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 :(
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, 15: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.
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.