Signal when end edit Item
Hi all!
I'm a beginner in QT.
I've a QTableWidget (name: tmp_table), and i putting Items on it by:
Code:
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!
Re: Signal when end edit Item
have a look at this signal QTableWidget::itemChanged.
Re: Signal when end edit Item
I've tried this :/
Unfortunately itemChanged is calling when Item are creating and putting into TableWiew, non when user end editing :/
Re: Signal when end edit Item
I dont understand. do you need to process an user's input in an item widget?
Re: Signal when end edit Item
The right signal should be QTableWidget::cellChanged ( int row, int column ). It is emitted when the content has changed = editing finished.
Re: Signal when end edit Item
Quote:
Originally Posted by
Lykurg
it's almost equal to that which I specified
Code:
void QTableWidgetPrivate
::_q_emitItemChanged
(const QModelIndex &index
) {
emit q->itemChanged(item);
emit q->cellChanged(index.row(), index.column());
}
:)
Re: Signal when end edit Item
Re: Signal when end edit Item
Quote:
Originally Posted by
spirit
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
Re: Signal when end edit Item
Quote:
Originally Posted by
spirit
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.
Re: Signal when end edit Item
maybe it's not a best solution,but anyway, block signals when you create items and then you can use itemChanged or cellChanged. :)
Re: Signal when end edit Item
Quote:
Originally Posted by
spirit
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:
Code:
tmp_table->setItem(row, col++, newItem1);
?
Re: Signal when end edit Item
try this
Code:
const bool isBlocked = tmp_table->blockSignals(true);
//add items here
tmp_table->blockSignals(isBlocked);
Re: Signal when end edit Item
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...
Code:
connect(ui.pTblItems->itemDelegate(), &QAbstractItemDelegate::commitData, this, &MyWidget::OnTblItemsCommitData);
Then implement the slot like this...
Code:
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.