PDA

View Full Version : QMenu not working when clicked



qtnewbi3
22nd November 2011, 16:07
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)




#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenuBar>
#include <QTextEdit>
#include <QLayout>
#include <QDockWidget>
#include <QTabWidget>
#include <QLabel>
#include <QContextMenuEvent>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{

QTabWidget *tab = new QTabWidget(this);
QWidget *newTab = new QWidget(tab);
tab->addTab(newTab,"ABCD");
QLabel *test = new QLabel("XYZ");
QMenuBar *menuBar = new QMenuBar(newTab);
QMenu* menu= menuBar->addMenu(tr("&tAB MENU"));
menu->addAction("blaah");
menu->addMenu("EFGH");
tab->setGeometry(0,0,500,500);

ui->setupUi(this);

}

MainWindow::~MainWindow()
{
delete ui;
}

ChrisW67
23rd November 2011, 00:21
Works fine here if you add it to the layout of the main window (you are not doing that in your example).

qtnewbi3
28th November 2011, 19:59
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.