Results 1 to 3 of 3

Thread: QMenu not working when clicked

  1. #1
    Join Date
    Jul 2011
    Posts
    31
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3
    Platforms
    MacOS X

    Default QMenu not working when clicked

    Hi,

    I am trying to create a menu within another widget and was trying it out in a Tabbed Widget. I was able to create the menu in a tab but it doesn't open when I click on it. However, if i use "Alt + t" which was the shortcut i set it to, then it works.

    Can anyone try it out and tell me if im missing an eventfilter or something. As I was under the impression that QMenu doesnt need any other reimplementation.

    Here is the code for the default widget created using QtCreator (mainwindow.cpp)



    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QMenuBar>
    4. #include <QTextEdit>
    5. #include <QLayout>
    6. #include <QDockWidget>
    7. #include <QTabWidget>
    8. #include <QLabel>
    9. #include <QContextMenuEvent>
    10.  
    11.  
    12. MainWindow::MainWindow(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWindow)
    15. {
    16.  
    17. QTabWidget *tab = new QTabWidget(this);
    18. QWidget *newTab = new QWidget(tab);
    19. tab->addTab(newTab,"ABCD");
    20. QLabel *test = new QLabel("XYZ");
    21. QMenuBar *menuBar = new QMenuBar(newTab);
    22. QMenu* menu= menuBar->addMenu(tr("&tAB MENU"));
    23. menu->addAction("blaah");
    24. menu->addMenu("EFGH");
    25. tab->setGeometry(0,0,500,500);
    26.  
    27. ui->setupUi(this);
    28.  
    29. }
    30.  
    31. MainWindow::~MainWindow()
    32. {
    33. delete ui;
    34. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMenu not working when clicked

    Works fine here if you add it to the layout of the main window (you are not doing that in your example).

  3. #3
    Join Date
    Jul 2011
    Posts
    31
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QMenu not working when clicked

    I am trying to do it without layout though... I got it to work in many different ways. The reason I ask is if I can see it then it must be there, so how come i cant click it.

Similar Threads

  1. QLabel::clicked()
    By sabeesh in forum Qt Programming
    Replies: 16
    Last Post: 1st August 2012, 03:17
  2. Qpushbutton clicked()
    By sasori1512 in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2011, 02:03
  3. connectSlotsByName and clicked()
    By becrux in forum Qt Programming
    Replies: 5
    Last Post: 2nd December 2009, 07:05
  4. QMenu popup: how close when clicked outside
    By powermax in forum Qt Programming
    Replies: 5
    Last Post: 4th March 2009, 03:18
  5. disable myself when clicked
    By nifei in forum Qt Programming
    Replies: 6
    Last Post: 19th February 2009, 10:01

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.