Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second
-
Linux: Ubuntu 17.10 64 Bit and Ubuntu 14.04 32 Bit
Windows: Windows 7 64 Bit -
The problem is here basically it has to delay the editing because otherwise a double-click would be interpreted as 2 separate clicks.
In release mode it's definetly not 1 sec but around 400ms -
As per @VRonin's reply, the Qt code resolves to:
/*! \property QApplication::doubleClickInterval \brief the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used. */ void QApplication::setDoubleClickInterval(int ms) { QGuiApplication::styleHints()->setMouseDoubleClickInterval(ms); } int QApplication::doubleClickInterval() { return QGuiApplication::styleHints()->mouseDoubleClickInterval(); }
So presumably if it really bothers you might do something about making your own call to
QApplication::setDoubleClickInterval()
to set it to a lower value. You might be able to do this just for the duration of your particular usage case, and have it restored to default the rest of the time.@VRonin
One thing I do not see from your answer is the OP's:- click cell "Aqua" => editing starts immediately
- hit Escape-Key to leave cell "Aqua"
- click cell "Aqua" a second time => editing starts with a delay of ca 1 second
I don't see why the delay applies in #7 but not in #5?
-
@JonB said in Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second:
I don't see why the delay applies in #7 but not in #5?
Because the delay only applies
if (trigger == SelectedClicked)
A possible solution for your problem is to subclass the view, reimplementing
bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event)
to changeSelectedClicked
toNoEditTrigger
and call the base class -
@JonB
VRonin is right, the delay only happens, if a selected cell is clicked to edit again.
This is the differende of #7 to #5.@JonB
the solution to use setDoubleClickInterval(int ms) works partially but not for everything in our program. E. g. with setDoubleClickInterval(0) the delay is gone, but Combo Boxes will open and close with one click (they then get a doubleclick?).So we tried to solution of @VRonin (subclass the view, reimplement edit).
This works for us, but it is a little bit of software overhead to workaround the problem.@VRonin @JonB
Seems there is some kind of "SingleClicked" missing in Qt to detect a single mouse click on a
selected editable cell.
We don't clearly see what a single click on a selected cell has to do with double clicks?Thanks for the solutions!
-
@linuxbastler said in Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second:
We don't clearly see what a single click on a selected cell has to do with double clicks?
Say you have
tableWidget.setEditTriggers(QAbstractItemView::SelectedClicked);
and you have something likeconnect(&tableWidget,&QAbstractItemView::doubleClicked,[]()->void{qDebug("Double Clicked!");});
instead of step 7, double-click on "Aqua". when you release the mouse and no delay is set, the editing starts, then you have a further mousepress+mouserelease that puts the cursor at the mouse position. This is not the expected behaviour, the correct one would be to execute the slot. Basically the problem is that at the time of the first mouserelease there is no way of knowing if the user intends to double-click or not so we have to wait and see
-
@linuxbastler
As @VRonin has explained above, every system does have to have some delay way of deciding whether a click is "standalone" or the start of a "double-click". And they have to do that by some delay after the first click to see if there is a second click coming. So they all have to do that, it's just a question of how long the delay is. -
we do not use doubleclick in this QTableWidget because we are on a touch device.
Would be nice to have some configuration / settings to configure doubleclick in this situation -
If you don't use doubleclick then the "reimplement edit() in the view" solution is what you are after. You can actually make it a template to make it so you just need to change 1 line in your existing code:
template<class T> class NoDelayView : public T{ #ifdef Q_COMPILER_STATIC_ASSERT static_assert(std::is_base_of<QAbstractItemView,T>::value,"Template argument must be a QAbstractItemView"); #endif Q_DISABLE_COPY(NoDelayView); public: explicit NoDelayView(QWidget* parent = Q_NULLPTR) : T(parent) {} protected: bool edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event) Q_DECL_OVERRIDE{ return T::edit(index, trigger == QAbstractItemView::SelectedClicked ? QAbstractItemView::AllEditTriggers : trigger, event); } };
-
@VRonin
ok, we got the idea of subclassing the view and reimplementing bool edit().
This solution is working for us, thanks!
The template solution seems to be elegant but we did not get it running with the "Star Delegate Example" in the first try. -
@linuxbastler said in Problem with delegates: repeated editing of same cell in QTableWidget has delay of ca 1 second:
The template solution seems to be elegant but we did not get it running with the "Star Delegate Example" in the first try.
Fixed a few typos up there, now just replace
QTableWidget tableWidget(4, 4);
withNoDelayView<QTableWidget> tableWidget; tableWidget.setRowCount(4); tableWidget.setColumnCount(4);
-
ok, the template solution is also working here.
Thanks a lot for your help!