QTable view diference between clicked and double-clicked signal
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
Re: QTable view diference between clicked and double-clicked signal
Quote:
Originally Posted by
nbilber
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.
Re: QTable view diference between clicked and double-clicked signal
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
Re: QTable view diference between clicked and double-clicked signal
How does "doesn't work" manifest itself?
Re: QTable view diference between clicked and double-clicked signal
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 ?
Re: QTable view diference between clicked and double-clicked signal
Why the Qt::QueuedConnection?
Cheers,
_
Re: QTable view diference between clicked and double-clicked signal
The order of signals was fired is important.
single click -> double click is diferent from double click -> single click
Cheers
Re: QTable view diference between clicked and double-clicked signal
Quote:
Originally Posted by
nbilber
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?
Re: QTable view diference between clicked and double-clicked signal
Hi
using Qt::QueuedConnection was the way that I find to ensure the order of clicks !
cheers