Results 1 to 19 of 19

Thread: Eventfilter problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter problem

    When I hit Enter in TExtedit I would like to enter this section in KeypressEvent:

    Qt Code:
    1. if(key == Qt::Key_Control ||
    2. key == Qt::Key_Shift ||
    3. key == Qt::Key_Alt ||
    4. key == Qt::Key_Meta ||
    5. key == Qt::Key_Return ||
    6. key == Qt::Key_Enter )
    7. {
    8. qDebug() << "Single click of special key: Ctrl, Shift, Alt or Meta or Enter/Return";
    9. qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText);
    10. return;
    11. }
    To copy to clipboard, switch view to plain text mode 

    But I have no output.

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

    Default Re: Eventfilter problem

    But your event filter method is being called - so just step through and see where the code is going and why - you have to debug - its pars of software development.
    See what key you actually get, and that the code runs the way you actually meant.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter problem

    Thats the problem. When I hit Ctrl+d or F1 or only Ctrl I run into my
    Qt Code:
    1. MainWindow::keyPressEvent(QKeyEvent* event)
    To copy to clipboard, switch view to plain text mode 
    But when I only press Enter I get a carriage return in my textedit but no event is triggered so I cant debug.

    So when I reimplement my Textedit::keyPressEvent

    and call
    Qt Code:
    1. if(e->key() == Qt::Key_Return)
    2. qDebug() << "Hallo";
    To copy to clipboard, switch view to plain text mode 

    I get my output;

    I provide an example project where you can see it if you can surely(when you have the time & fun). When I handle return in MAinwindow no event is triggered. When I reimplement it again in Textedit I can catch the event.
    I cannot add a zip archiv....
    Last edited by codeman; 3rd July 2012 at 15:23.

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

    Default Re: Eventfilter problem

    But when I only press Enter I get a carriage return in my textedit but no event is triggered so I cant debug.
    Oh, I read to fast your previous answer, I thought you DO get a qDebug().

    But you can debug - set a break point in the first line of the function - that is the only sure way to know.

    In the information you provided I can't see anything else.
    Post you project, and i will try it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter problem

    So here is the project:
    installEvent.zip
    By the way the breakpoint in my event method and hitting Enter does not enter this method.

    Thanx in advance

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

    Default Re: Eventfilter problem

    MainWindow::keyPressEvent()
    should be
    MainWindow::eventFilter()
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter problem

    And what is inside the bracket of your event method

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

    Default Re: Eventfilter problem

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter problem

    Is this correct:
    Qt Code:
    1. MainWindow::eventFilter(QKeyEvent* event)
    To copy to clipboard, switch view to plain text mode 
    MainWindow::eventFilter(QKeyEvent* event)

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

    Default Re: Eventfilter problem

    Please read the eventFilter docs.
    Don't expect to be fed every little detail.
    http://qt-project.org/doc/qt-4.8/qob...ml#eventFilter
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter problem

    Ok thank you very much

Similar Threads

  1. EventFilter problem
    By aruval3 in forum Qt Programming
    Replies: 10
    Last Post: 17th November 2011, 21:22
  2. problem in eventFilter of QGraphicsView()
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 20th July 2009, 12:28
  3. sceneEventFilter or eventFilter
    By zgulser in forum Qt Programming
    Replies: 7
    Last Post: 4th May 2009, 07:50
  4. eventFilter in Console App
    By KaptainKarl in forum Newbie
    Replies: 3
    Last Post: 20th December 2008, 00:27
  5. paintEvent in eventFilter
    By kernel_panic in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 20:59

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
  •  
Qt is a trademark of The Qt Company.