How to detect if a data in a QTableWidget cell is about to change
what i mean is if someone double clicks it or pressing F2 in order to start typing i tried the signals:
@void cellDoubleClicked(int row, int column)@
@void cellEntered(int row, int column)@
@void itemDoubleClicked(QTableWidgetItem * item)@
@void itemEntered(QTableWidgetItem * item)@
but the slots doesn't get excuted
please note that i don't mean that the data is already changed ,but i mean before the data gets changed
Hi, The cellEntered is a mouse operation detection, not a clicked signal, so you have to turn on the mousetracking option (see docs).
The cellDoubleClicked should work or the
@void QTableWidget::cellPressed(int row, int column) [signal]
void QTableWidget::cellActivated(int row, int column) [signal]
should both do the trick. My guess is that your connect isn't valid, so Qt doesn't make a connection for your event, so your slot doesn't get called. Check your application output for errors on connect function.
Why don't you try reimplementing
If you want to detect changes, catch the proper signal.
These should be emitted right before the new data is made visible, at least that's the case in other views I have experience with.
If that doesn't work, create the signal you need. Subclass "QStyledItemDelegate":http://qt-project.org/doc/qt-5.1/qtwidgets/qstyleditemdelegate.html and reimplement (in the most basic manner) "QAbstractItemDelegate::setModelData":http://qt-project.org/doc/qt-5.1/qtwidgets/qabstractitemdelegate.html#setModelData . Somewhat like this:
@void YourStyledItemDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
emit YourCustomSignal(index);//if you need to transmit any data, index should contain enough information
QStyledItemDelegate::setModelData(editor, model, index);
And in the end you need to use your custom ItemDelegate with this function, which should be public for your QTableWidget: