Telling apart single click and double click in QTableView
Hi,
I'm using a QTableView (cannot change to QTableWidget) and need a Delegate (not an editor) to do different actions on single and double mouse clicks. The basic idea I came up with is to start a QTimer on a QEvent::MouseButtonRelease and either stop it on receiving a QEvent::MouseButtonDblClick and depending on the program state maybe open a new QWindow or if no double click event is received to change something on the delegate.
The other QWindow is started through the doubleClicked signal in a controller class:
This is my Delegate's event handling:
Code:
{
if (QEvent::MouseButtonRelease) {
qDebug() << "single click";
m_timer->start();
event->accept();
return true;
}
else if (event
->type
() == QEvent::MouseButtonDblClick) {
qDebug() << "double click";
m_timer->stop();
event->accept();
return true;
}
else
{
return false;
}
}
I saw in the source code, that QAbstractItemView::mouseDoubleClickEvent is sending out a mouse press event like QWidget::mouseDoubleClickEvent so I overloaded it with an empty function in my QTableView and verified it isn't run.
But I get mixed results.
Double click on MyDelegate while it is focused and no new QWindow is started:
Code:
single click
double click
single click
Where do I get the excess single click event from?
(in this case my timer is started again and the undesired single click action is executed, but a double click should be ignored if no new QWindow is started)
Double click on MyDelegate while it is focused and a new QWindow is started:
Code:
single click
double click
Why do those situations behave differently?
To sum it up:
I need my delegate to
* always react on a single click (i.e. repaint differently)
* either start a new QWindow or ignore a double click, depending on programs state
Any suggestions how I can achieve this? Completely different approaches are welcome as well.
Cheers
jgirlich
Re: Telling apart single click and double click in QTableView
Huh, no suggestions? Did I ask my question in a bad way or is there nobody who can explain the Qt event behaviour to me?
Anyway, best solution I found so far: Using a timer to delay the execution of 'maybeOpenQWindow' so the second single click event goes through and I can stop my m_timer on it.
Code:
{
if (QEvent::MouseButtonRelease) {
qDebug() << "single click";
if (m_timer->isActive())
m_timer->stop();
else
m_timer->start();
event->accept();
return true;
}
else
{
return false;
}
}
And the slot looks like this:
Code:
{
QTimer::singleShot(75,
this,
SLOT(reallyMaybeOpenQWindow
()));
}
I know it's really dirty, but since I don't seem to understand the event inside a QTableView and it's delegates it's the only way I found to get it working.