Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QTabWidget over MenuBar
Forum Updated to NodeBB v4.3 + New Features

[Solved] QTabWidget over MenuBar

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    huckfinn
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        huckfinn
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            huckfinn
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Could you show your code, please?

              1 Reply Last reply
              0
              • H Offline
                H Offline
                huckfinn
                wrote on last edited by
                #7

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

                @

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  huckfinn
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    octal
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      huckfinn
                      wrote on last edited by
                      #10

                      Perfect, thank you everybody fr your help!
                      Cheers huck

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved