Results 1 to 3 of 3

Thread: QTextEdit not receiving MouseButtonDblClick or MouseButtonPress

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QTextEdit not receiving MouseButtonDblClick or MouseButtonPress

    Here's my event filter:

    Qt Code:
    1. bool MainWindow::eventFilter(QObject *object, QEvent *event)
    2. {
    3.  
    4. //QEvent::MouseButtonDblClick
    5. if(event->type() == QEvent::MouseButtonPress)
    6. {
    7. if(object == ui->myQTextEdit)
    8. {
    9. assert(0);
    10. }
    11. else if(object == ui->myQLineEdit)
    12. {
    13. assert(0);
    14. }
    15. }
    16.  
    17. return QMainWindow::eventFilter(object, event);
    18. }
    To copy to clipboard, switch view to plain text mode 

    Here's how I'm setting it up:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    3. {
    4. ui->setupUi(this);
    5.  
    6. ui->myQTextEdit->installEventFilter(this);
    7. ui->myQLineEdit->installEventFilter(this);
    8. }
    To copy to clipboard, switch view to plain text mode 

    When I click on the QLineEdit, the assert triggers. Good. When I click on the QTextEdit, it does not trigger. The same happens with QEvent::MouseButtonDblClick. Double clicks work on the QLineEdit, and not on the QTextEdit.

    I know the filter is set up right, because using something like QEvent::Enter triggers the assert on both QLineEdits and QTextEdits. (Also, I have more than one QTextEdit, and it doesn't work on either)

    And here's the odd thing, the edging around the QTextEdits are receptive to presses and double clicks and trigger the asserts. The textual part of the QTextEdits are the parts that aren't receiving them, however.

    Could someone confirm the ability to capture double and single clicks on QTextEdits in Qt 4.5? What did I do wrong?

    Thank you in advance.

  2. #2
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QTextEdit not receiving MouseButtonDblClick or MouseButtonPress

    It looks there is something to do with viewport of textEditor.
    You can try this. It worked for me.
    Qt Code:
    1. QWidget * pWidget = myQTextEdit->viewport();
    2. pWidget->installEventFilter(this);
    3.  
    4. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    5. {
    6. if(event->type() == QEvent::MouseButtonPress)
    7. {
    8. if(obj == pWidget)
    9. {
    10. qDebug("TextEdit");
    11. }
    12. }
    13.  
    14. // pass the event on to the parent class
    15. return QMainWindow::eventFilter(obj, event);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

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

    ComServant (10th April 2009)

  4. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default

    Hey, that did it for me, thank you!

    I was thinking there was some bug, or else that I'd have to create my own version of QTextEdit (which I wouldn't know how to do) to get it working.

    Captures both presses and double clicks just fine, thanks.

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.