[Solved] QTabWidget over MenuBar
-
Hello,
I have a manubar already on top of my MainWindow as you can see on the pic. !http://img705.imageshack.us/img705/8499/screengx.png(MainWindow)!
further on I would like to create a Tab first with on, "test" and later on with other.
Therfore I found examples, but as you can see the Widgets overlap.@
QWidget *w = new QWidget;
dTabWidget = new QTabWidget(this);dTabWidget->addTab(w, "Test"); dTabWidget->show(); mainLayout = new QVBoxLayout;
// mainLayout->addWidget(menuBar());
mainLayout->addWidget(dTabWidget);// dTabWidget = new QTabWidget(mainLayout);
// initTab = new InitImportTab(dTabWidget);
setLayout(mainLayout);
@how can I have the menubar on top and then the tabs?
Thank you fpr you hints..
-
Just do this:
@
dTabWidget = new QTabWidget(0);
this->setCentralWidget(dTabWidget);
@What was happening, is that centralWidget() returns 0 by default: no central widget has been set. Creating a widget with a 0 parent results in a top level widget. Thus, you end up with two widgets. In the code snippet I gave you, this does not happen, as QMainWindow will set the correct parent for you as soon as you invoke setCentralWidget.
-
Yes of course:
@
initTab = new InitImportTab; // ==QWidget
dTabWidget = new QTabWidget(0);
this->setCentralWidget(dTabWidget);dTabWidget->addTab(initTab, "Test"); dTabWidget->show(); mainLayout = new QVBoxLayout(this);
// mainLayout->addWidget(menuBar());
mainLayout->addWidget(dTabWidget);setLayout(mainLayout);
@
-
Then create a QWidget, set a layout and call setCentralWidget :
@
QWidget *mainWidget = new QWidget;QTabWidget *tabWidget = new QTabWidget;
QPushButton *button = new QPushButton("My button");QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(button);
mainWidget->setLayout(mainLayout);setCentralWidget(mainWidget);
@