View Full Version : Signal when end edit Item
TomASS
17th April 2009, 16:44
Hi all!
I'm a beginner in QT.
I've a QTableWidget (name: tmp_table), and i putting Items on it by:
QTableWidgetItem *newItem1 = new QTableWidgetItem(tr("%1").arg(query.value(1).toString()));
tmp_table->setItem(row, col++, newItem1);
Items are editable (on click or press F2).
I would like to call ex. some_function() (ex. save value in the database) when user end editing a datan int to a QTableWidgetItem.
How can I do it?
Thaks a lot!
spirit
17th April 2009, 16:45
have a look at this signal QTableWidget::itemChanged.
TomASS
17th April 2009, 16:51
I've tried this :/
Unfortunately itemChanged is calling when Item are creating and putting into TableWiew, non when user end editing :/
spirit
17th April 2009, 16:53
I dont understand. do you need to process an user's input in an item widget?
Lykurg
17th April 2009, 16:57
The right signal should be QTableWidget::cellChanged ( int row, int column ). It is emitted when the content has changed = editing finished.
spirit
17th April 2009, 17:00
The right signal should be QTableWidget::cellChanged ( int row, int column ). It is emitted when the content has changed = editing finished.
it's almost equal to that which I specified
void QTableWidgetPrivate::_q_emitItemChanged(const QModelIndex &index)
{
Q_Q(QTableWidget);
if (QTableWidgetItem *item = model()->item(index))
emit q->itemChanged(item);
emit q->cellChanged(index.row(), index.column());
}
:)
jpn
17th April 2009, 17:03
See QxtTableWidget (http://doc.libqxt.org/0.4.0/classQxtTableWidget.html).
Lykurg
17th April 2009, 17:26
it's almost equal to that which I specified
Right, I see, while switching from the forum to the docs my brain substitute itemChanged with currentItemChanged which leads to my superfluous reply... :o
TomASS
17th April 2009, 17:33
I dont understand. do you need to process an user's input in an item widget?
I need to save data (call function, save_data() ) when user change text in Item.
spirit
17th April 2009, 17:38
maybe it's not a best solution,but anyway, block signals when you create items and then you can use itemChanged or cellChanged. :)
TomASS
17th April 2009, 17:57
maybe it's not a best solution,but anyway, block signals when you create items and then you can use itemChanged or cellChanged. :)
ok! It's seems to work cellChanged, almost:
how to disable cellChange when I'm creating and putting Item into TableWiew:
QTableWidgetItem *newItem1 = new QTableWidgetItem(tr("%1").arg(query.value(1).toString()));
tmp_table->setItem(row, col++, newItem1);
?
spirit
20th April 2009, 09:48
try this
const bool isBlocked = tmp_table->blockSignals(true);
//add items here
tmp_table->blockSignals(isBlocked);
lclemens@gmail.com
20th June 2015, 21:57
I haven't tested with QTableWidget, but I know that with QListWidget there's a much better solution than using QListWidget::itemChanged and trying to block all the signals when adding/changing colors/setting flags, and doing anything else that "changes" the item.
Try this...
connect(ui.pTblItems->itemDelegate(), &QAbstractItemDelegate::commitData, this, &MyWidget::OnTblItemsCommitData);
Then implement the slot like this...
void MyWidget::OnTblItemsCommitData(QWidget* pLineEdit)
{
QString strNewText = reinterpret_cast<QLineEdit*>(pLineEdit)->text();
int nRow = ui.pTblItems->currentRow();
// do whatever you need here....
}
Like I said... I only tried this for QListWidget, so who knows it might not work at all for the table widget, but the two classes are pretty similar so I wouldn't be surprised if it worked. You might have to tweak that code a bit to make it table widget specific.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.