QTableWidget editing signal
-
Hi all,
is there a way to know when a QTableWidgetItem is being edited?
My app is listening for UDP broadcast frames and I have a table reporting those records with some additional editable colums... the table is automalically refreshed when new data arrives... but I would like to stop the refresh if the user is actually editing an item into the table...
I've checked cellEntered(), cellPressed(), cellActivated(), cellDoubleClicked() and the corresponding item versions but none of them seems to tell me when the user is actually editing an item.
thanks for any hints Giampaolo
-
@iw2lsi
Yes: https://doc.qt.io/qt-5/qtablewidget.html#isPersistentEditorOpen. You'll have to loop through the items. Or, if you are sub-classingQTableWidgetItem
you could monitor https://doc.qt.io/qt-5/qtablewidget.html#openPersistentEditor & https://doc.qt.io/qt-5/qtablewidget.html#closePersistentEditor to keep your own track of an item being edited to avoid searching. -
You can just add a custom signal to the delegate.
class SignalEditDelegate : public QStyledItemDelegate { Q_OBJECT Q_DISABLE_COPY_MOVE(SignalEditDelegate) public: explicit SignalEditDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent) {} void setEditorData(QWidget *editor, const QModelIndex &index) const override { QStyledItemDelegate::setEditorData(editor, index); editStarted(); } void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override { QStyledItemDelegate::setModelData(editor, model, index); editFinished(); } signals: void editStarted() const; void editFinished() const; };
Then you use it via:
SignalEditDelegate* signalDelegate =new SignalEditDelegate(this) connect(signalDelegate,&SignalEditDelegate::editStarted, /*...*/); connect(signalDelegate,&SignalEditDelegate::editFinished, /*...*/); tableWidget->setItemDelegate(signalDelegate);
-
@VRonin Hello Ronin... I'm probably missing something but I'm getting various errors that I do not know how to fix...
SignalEditDelegate.h:15:5: error: unknown type name 'Q_DISABLE_COPY_MOVE'
note: Q_DISABLE_COPY(SignalEditDelegate) seems to work.SignalEditDelegate.h:24:31: error: cannot initialize object parameter of type 'const QStyledItemDelegate' with an expression of type 'const SignalEditDelegate'
SignalEditDelegate.h:25:11: error: 'this' argument to member function 'editStarted' has type 'const SignalEditDelegate', but function is not marked constGiampaolo
-
@iw2lsi said in QTableWidget editing signal:
SignalEditDelegate.h:15:5: error: unknown type name 'Q_DISABLE_COPY_MOVE'
note: Q_DISABLE_COPY(SignalEditDelegate) seems to work.Q_DISABLE_COPY_MOVE
was added to Qt recently (5.13). you can useQ_DISABLE_COPY
instead or just delete the line completelySignalEditDelegate.h:24:31: error: cannot initialize object parameter of type 'const QStyledItemDelegate' with an expression of type 'const SignalEditDelegate'
SignalEditDelegate.h:25:11: error: 'this' argument to member function 'editStarted' has type 'const SignalEditDelegate', but function is not marked constthe old const-signal phantomime. of course. Just change
signals: void editStarted(); void editFinished();
to
signals: void editStarted() const; void editFinished() const;
-
@JonB said in QTableWidget editing signal:
Would you mind explaining briefly when you either must or choose to do so, please?
Signals can be declared
const
but it has no material effect. When moc creates the implementation of the signal, sender getsconst_cast
ed to lose theconst
anyway. -
J JonB referenced this topic on