Trying to put things that were already mentioned together: if you are not worried about a slight lag in reaction to a single click, you only need to set up a QTimer
in your class which you start on single click and stop if you receive a second click within a certain time window.
You then just connect the timeout of the timer to the slot that does what you want to do on a single click.
One way of setting this up (certainly not the only way and probably not the most elegant) you see below:
mytreeview.h
#ifndef MYTREEVIEW_H
#define MYTREEVIEW_H
#include <QTreeView>
#include <QTimer>
class MyTreeView: public QTreeView
{
Q_OBJECT
public:
MyTreeView(QWidget *parent = 0);
protected:
virtual void mouseDoubleClickEvent(QMouseEvent * event);
virtual void mousePressEvent(QMouseEvent * event);
private:
QTimer timer;
private slots:
void onSingleClick();
};
mytreeview.cpp
#include "mytreeview.h"
#include <QtCore>
MyTreeView::MyTreeView(QWidget *parent) : QTreeView(parent)
{
connect(&timer,SIGNAL(timeout()),this,SLOT(onSingleClick()));
}
void MyTreeView::mouseDoubleClickEvent(QMouseEvent * event)
{
Q_UNUSED(event);
qDebug() << "This happens on double click";
timer.stop();
}
void MyTreeView::mousePressEvent(QMouseEvent * event)
{
Q_UNUSED(event);
timer.start(250);
}
void MyTreeView::onSingleClick()
{
qDebug() << "This happens on single click";
timer.stop();
}
Let me know if this helps.