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;
}
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;
}