Results 1 to 3 of 3

Thread: click on menubar item (without submenu actions)

  1. #1
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default click on menubar item (without submenu actions)

    Hi

    how can I catch left click on menubar item (without submenu actions) in mainwindow?
    I want to view dockwidgets and toolbar list popup (such as when you do rigth click on menubar / toolbar), when there is left click on a menubar item (with name &view).

    regards
    navid

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: click on menubar item (without submenu actions)

    Quote Originally Posted by navid View Post
    Hi

    how can I catch left click on menubar item (without submenu actions) in mainwindow?
    I want to view dockwidgets and toolbar list popup (such as when you do rigth click on menubar / toolbar), when there is left click on a menubar item (with name &view).

    regards
    navid
    Install event filters.

  3. #3
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: click on menubar item (without submenu actions)

    source code (from help of Qt4.6) is
    Qt Code:
    1. protected:
    2. bool eventFilter(QObject *obj, QEvent *ev);
    3.  
    4. MainWindow::MainWindow()
    5. {
    6. ui->menuBar->installEventFilter(this);
    7. }
    8.  
    9. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    10. {
    11. if (obj == ui->menuBar) {
    12. if (event->type() == QEvent::MouseButtonPress) {
    13. QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    14. qDebug() << "key pressed" << keyEvent->key();
    15. return true;
    16. } else {
    17. return false;
    18. }
    19. } else {
    20. // pass the event on to the parent class
    21. return QMainWindow::eventFilter(obj, event);
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    but for each time of click on the same menubar item, i receive a new number or receive the same number for different menubar items:

    Ate key press 9
    Ate key press 7
    Ate key press 7
    Ate key press 8
    Ate key press 8
    Ate key press 11
    Ate key press 10
    Ate key press 9
    Ate key press 9
    Ate key press 10
    Ate key press 10
    Ate key press 10
    Ate key press 10
    Ate key press 10
    Ate key press 10
    Ate key press 9
    Ate key press 9
    Ate key press 9
    Ate key press 9
    Ate key press 6
    Ate key press 6
    Ate key press 6

    what is the solution?

Similar Threads

  1. Menubar actions
    By srohit24 in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2009, 11:35
  2. Can't click menubar items / QPixMap doesn't show
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2008, 10:45
  3. Finding menuBar actions
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2008, 00:14
  4. TreeView click item not connecting
    By Big Duck in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2006, 19:38

Tags for this Thread

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.