PDA

View Full Version : QTable view diference between clicked and double-clicked signal



nbilber
8th July 2015, 21:09
Hi,

I have a custom table View with two signals clicked and double-clicked.

connect(this,SIGNAL(clicked(QModelIndex)),this,SLO T(clickedSlot(QModelIndex)));
connect(this,SIGNAL(doubleClicked(QModelIndex)),th is,SLOT(doubleClickedSlot(QModelIndex)));

Every time I do a double-clicked also invoques a clicked. That's a problems a need to distingue these two events.

It's possible to differentiate these two :mad:?


Kind regards
Nelson

wysota
8th July 2015, 21:32
Hi,

I have a custom table View with two signals clicked and double-clicked.

connect(this,SIGNAL(clicked(QModelIndex)),this,SLO T(clickedSlot(QModelIndex)));
connect(this,SIGNAL(doubleClicked(QModelIndex)),th is,SLOT(doubleClickedSlot(QModelIndex)));

Every time I do a double-clicked also invoques a clicked. That's a problems a need to distingue these two events.

It's possible to differentiate these two :mad:?

Well... yes and no. A click occurs because to double click you have to click and then click again during a defined period. When you click the first time, the framework doesn't know if you are going to click again or not, so it signals a click immediately and you cannot avoid that. What you can do is that you can start a timer with a short timeout when a click occurs and if double-click doesn't come before the timer fires, you will know that the click you received earlier is "real" and you should handle it as such. The downside is that all your single clicks are going to lag behind because of this mechanism.

nbilber
9th July 2015, 10:15
Hi,

I tried to implement your solution, but it doesn't work, even when I stop the signal fires

source code:
--------------


class myTableView:public QTableView
{
Q_OBJECT
public:
myTableView():QTableView()
{
timer_.setSingleShot(true);
timer_.setInterval(1000);

connect(this,SIGNAL(clicked(QModelIndex)),this,SLO T(clickedSlot(QModelIndex)));
connect(this,SIGNAL(doubleClicked(QModelIndex)),th is,SLOT(doubleClickedSlot(QModelIndex)));

connect(&timer_, SIGNAL(timeout()), this, SLOT(checkIfIsOneClick()), Qt::QueuedConnection);
}

~myTableView()
{
}

private slots:

void clickedSlot(QModelIndex index)
{
timer_.start();
qDebug() << "ONE CLICK - PART I";
}

void doubleClickedSlot(QModelIndex index)
{
timer_.stop();
qDebug() << "TWO CLICK";
}

void checkIfIsOneClick()
{
qDebug() << "ONE CLICK - PART II";
}

private:
QTimer timer_;

};



Thanks

wysota
9th July 2015, 10:55
How does "doesn't work" manifest itself?

nbilber
9th July 2015, 12:10
When I do a DoubleCLick it always do a click

void checkIfIsOneClick()
{
qDebug() << "ONE CLICK - PART II";
}

The timer fires a signal

How Can avoid this ?

anda_skoa
9th July 2015, 12:29
Why the Qt::QueuedConnection?

Cheers,
_

nbilber
9th July 2015, 13:44
The order of signals was fired is important.

single click -> double click is diferent from double click -> single click



Cheers

wysota
9th July 2015, 19:56
The order of signals was fired is important.

single click -> double click is diferent from double click -> single click

Is that a solution or the answer to anda_skoa's question?

nbilber
10th July 2015, 12:12
Hi

using Qt::QueuedConnection was the way that I find to ensure the order of clicks !


cheers