Results 1 to 9 of 9

Thread: QTable view diference between clicked and double-clicked signal

  1. #1
    Join Date
    Oct 2013
    Posts
    8
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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 ?


    Kind regards
    Nelson

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTable view diference between clicked and double-clicked signal

    Quote Originally Posted by nbilber View Post
    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 ?
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2013
    Posts
    8
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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 myTableViewublic 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTable view diference between clicked and double-clicked signal

    How does "doesn't work" manifest itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2013
    Posts
    8
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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 ?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTable view diference between clicked and double-clicked signal

    Why the Qt::QueuedConnection?

    Cheers,
    _

  7. #7
    Join Date
    Oct 2013
    Posts
    8
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTable view diference between clicked and double-clicked signal

    Quote Originally Posted by nbilber View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2013
    Posts
    8
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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

Similar Threads

  1. Replies: 3
    Last Post: 3rd April 2015, 07:46
  2. Replies: 3
    Last Post: 13th February 2012, 00:00
  3. double clicked on an item QTreeWidget
    By milli in forum Newbie
    Replies: 3
    Last Post: 7th May 2011, 22:49
  4. Getting the Id of a double clicked item
    By thefatladysingsopera in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2011, 15:18
  5. how can i get the QPushButton clicked on a QTable
    By showben in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2011, 16:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.