Results 1 to 7 of 7

Thread: Eventfilter Problem

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

    Default Eventfilter Problem

    Hello friends,

    I have a question. I have a 2 Qmainwindow. I put the one in the other as centralwidget to achieve the full height of the left and the right Dockwidget.I now have an outer QMainWindow and an inner QMainwindow. Then I add a buttomdockwidget with a textedit to inner QMainwindow. I would like to handle the event in the outer QMainwindow (
    Qt Code:
    1. MainWindow::eventFilter(QObject *obj, QEvent *event)
    To copy to clipboard, switch view to plain text mode 
    ) and I intall it
    Qt Code:
    1. this->mytextedit->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 
    By this I mean the outer QMainwindow. So now when I hit a "s" for example I have an output like this "ss". It doubles my input.

    Where is the misunderstanding of mine here?

    Thanx in advance

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

    Default Re: Eventfilter Problem

    What code did you put in the event filter?
    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
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter Problem

    Qt Code:
    1. //qDebug() << Q_FUNC_INFO << obj;
    2. int keyInt(0);
    3. Qt::Key key;
    4. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    5. keyInt = keyEvent->key();
    6. key = static_cast<Qt::Key>(keyInt);
    7.  
    8.  
    9.  
    10.  
    11. if (event->type() == QEvent::KeyPress)
    12. {
    13. if(key == Qt::Key_unknown)
    14. {
    15. return true;
    16. }
    17. if( key == Qt::Key_Control ||
    18. key == Qt::Key_Shift ||
    19. key == Qt::Key_Alt ||
    20. key == Qt::Key_Meta )
    21. {
    22. return true;
    23. }
    24. Qt::KeyboardModifiers modifiers = keyEvent->modifiers();
    25. QString keyText = keyEvent->text();
    26. qDebug() << "KEyTExt: " << keyText;
    27. if(modifiers & Qt::ShiftModifier)
    28. keyInt += Qt::SHIFT;
    29. if(modifiers & Qt::ControlModifier)
    30. keyInt += Qt::CTRL;
    31. if(modifiers & Qt::AltModifier)
    32. keyInt += Qt::ALT;
    33. if(modifiers & Qt::MetaModifier)
    34. keyInt += Qt::META;
    35.  
    36. QString objname = obj->objectName();
    37. QString keySequence = QKeySequence(keyInt).toString(QKeySequence::NativeText);
    38. if(this->_mapShortCutFunctor2.contains(objname) && this->_mapShortCutFunctor2[objname].contains(keySequence) )
    39. {
    40. (this->*_mapShortCutFunctor2[objname][keySequence])();
    41. return true;
    42. }
    43. }
    44. else
    45. {
    46. return QMainWindow::eventFilter(obj, event);
    47. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Eventfilter Problem

    You definitely shouldn't assume you'll only be getting key events in the filter. This code might crash on line #5. What exactly are you trying to do? Why aren't you using QShortCut and QAction objects?
    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
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Eventfilter Problem

    I try to collect all keypressed events or combinations of those in one place, where I can react depending on the object.

    Have you a better solution. I am learning by doing. Doing it wrong perhaps helps also to find out the right way;o)).

    I am open for any suggestions.

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

    Default Re: Eventfilter Problem

    The proper way would be to use a bunch of QAction instances (alternatively QShortcut instances here and there) and enable/disable them depending on the context.
    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.


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

    Default Re: Eventfilter Problem

    Ok thank you

Similar Threads

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

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.