Results 1 to 3 of 3

Thread: Detect widget doubleclick

  1. #1
    Join Date
    Jul 2015
    Posts
    20
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Detect widget doubleclick

    I have tried 2 things:
    1. mouseDoubleClickEvent
    It worked fine for unclickable widgets like QLabels but did not work for clickable ones like PlainTextEdit or PushButton.

    2. eventFilter
    Seems to work fine for QLabel as well.
    It works for PlainTextEdit but not as intended. It detects a double click only if i click at the very edge of widget (what is like 1 pixel). If I double click the main widget area(where you can put text in) nothing really happens.

    Qt Code:
    1. class myEventFilter: public QObject
    2. {
    3. public:
    4. myEventFilter(QObject *parent):QObject(parent) {};
    5.  
    6. bool eventFilter(QObject* object,QEvent* event)
    7. {
    8. if(event->type() == QEvent::MouseButtonDblClick)
    9. {
    10. qDebug() << "Widget double clicked";
    11. return true;
    12. }
    13. else
    14. return QObject::eventFilter(object,event);
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ui->plainTextEdit->installEventFilter(new myEventFilter(this));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Detect widget doubleclick

    For the plain text edit, install the even filter in the edit's viewport widget.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Grzyboo (28th July 2015)

  4. #3
    Join Date
    Jul 2015
    Posts
    20
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Detect widget doubleclick

    Oh, great, thanks for the advice.

Similar Threads

  1. Detect when a widget looses focus?
    By thomaspu in forum Qt Programming
    Replies: 11
    Last Post: 5th April 2021, 15:58
  2. DoubleClick on QwtLegend
    By hassinoss in forum Qwt
    Replies: 2
    Last Post: 11th February 2014, 17:37
  3. Replies: 1
    Last Post: 19th July 2013, 23:20
  4. Replies: 2
    Last Post: 1st January 2012, 23:22
  5. Replies: 1
    Last Post: 30th March 2011, 15:29

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.