[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..



  • You should create a new QTabWidget, and set that as the centralWidget of your main window.



  • I have tried it, but then I have two seperate windows. My initial window the the menubars and another smaller window with just that tab.
    @
    dTabWidget = new QTabWidget(centralWidget());
    @



  • 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.



  • Ok, I have set the centralWidget.
    Now, I have the same problem as on beginning, my tabs are over my menubar..

    I can't click on "Members" in the screenshot above..



  • Could you show your code, please?



  • 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);
    

    @



  • Ah ok, my Layout is faulty.

    Without Layout looks perfect. Anyway, I would prefer a Layout, because I will add Buttons and so an later on, and with layouts its much more organized..



  • 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);
    @



  • Perfect, thank you everybody fr your help!
    Cheers huck


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.