Results 1 to 6 of 6

Thread: 2 times click instead of double click (eg. renaming)

  1. #1
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default 2 times click instead of double click (eg. renaming)

    Hi all,

    I ame looking for a way to check whether a user pressed the left mouse button twice within a minimal time periode, but which is different from the double click signal. I want to use this for renaming a qlistview item as this is normally done. At the moment I use the double click signal and the renaming works fine, but I would like to connect the renaming to the "2 times click" as this is normally done for renaming. How can I do this?

    Thanx!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: 2 times click instead of double click (eg. renaming)

    You can use the QWidget::mousePressEvent() and mesure the time between two of those...

  3. #3
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: 2 times click instead of double click (eg. renaming)

    I will try that.

    Do you have any idea what the usual time delay between the two clicks is when renaming an item?

  4. #4
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 2 times click instead of double click (eg. renaming)

    For sure it should be more than QApplication::doubleClickInterval ()

  5. #5
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 2 times click instead of double click (eg. renaming)

    Quote Originally Posted by edb
    Hi all,

    I ame looking for a way to check whether a user pressed the left mouse button twice within a minimal time periode, but which is different from the double click signal. I want to use this for renaming a qlistview item as this is normally done. At the moment I use the double click signal and the renaming works fine, but I would like to connect the renaming to the "2 times click" as this is normally done for renaming. How can I do this?

    Thanx!
    I have a solution!

    You can connect QListWidget::itemClicked(QListWidgetItem* item) signal to a slot (i.e. MyWidget::listItemClicked(QListWidgetItem* item)) like
    Qt Code:
    1. void MyWidget::listItemClicked(QListWidgetItem* item)
    2. {
    3. if(listWidget->itemIsSelected(item))
    4. {
    5. // Clicked item is previously selected
    6. // Edit item
    7. }
    8. else
    9. {
    10. // Select the item
    11. listWidget->setCurrentItem(item);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    In this way user can edit list item text selecting item and then clicking on it (like Windows icon text).

    Bye
    A camel can go 14 days without drink,
    I can't!!!

  6. #6
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: 2 times click instead of double click (eg. renaming)

    Something very strange is happening... During my testing for the sollutions given above I came accross the following:

    I have written some testcode as shown below . If you run this, you can see that renaming seems to be already implemented in QT and all you have to do is catch the itemRenamed.... I have never seen this before, but it seems to work fine! The connection below makes sure you can do whathever you want when an item is renamed...

    mylistview.h

    Qt Code:
    1. #ifndef mylistview_h
    2. #define mylistview_h
    3.  
    4. #include <qlistview.h>
    5. #include <iostream>
    6.  
    7. class MyListView : public QListView
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. MyListView(QWidget* parent = 0, const char* name = 0, WFlags f =0);
    13.  
    14. public slots:
    15. void slotTestRename();
    16. };
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 




    mylistview.cpp
    Qt Code:
    1. #include "mylistview.h"
    2.  
    3. MyListView::MyListView(QWidget* parent, const char* name, WFlags f)
    4. : QListView(parent, name, f)
    5. {
    6. connect(this, SIGNAL(itemRenamed(QListViewItem* , int)), this, SLOT(slotTestRename()));
    7. }
    8. void MyListView::slotTestRename()
    9. {
    10. std::cout << "RENAMED " << std::endl;
    11. }
    To copy to clipboard, switch view to plain text mode 

    mainfile:
    Qt Code:
    1. #ifdef HAVE_CONFIG_H
    2. #include <config.h>
    3. #endif
    4.  
    5. #include <stdio.h>
    6. #include <stdlib.h>
    7. #include <qapplication.h>
    8. #include <mylistview.h>
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication a(argc,argv);
    13.  
    14. MyListView* listview = new MyListView();
    15. listview->addColumn("testcolumn");
    16.  
    17. a.setMainWidget(listview);
    18.  
    19. QListViewItem* item = new QListViewItem(listview);
    20.  
    21. item->setText(0, "trial");
    22. item->setRenameEnabled(0, true);
    23.  
    24.  
    25. listview->show();
    26.  
    27. //myMainWindow->showMaximized();
    28.  
    29. return a.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 15:12
  2. Replies: 2
    Last Post: 12th January 2009, 00:24
  3. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 05:32

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.