Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [SOLVED] Adding QMenubar under every tab of QTabWidget

    General and Desktop
    qtabwidget qmenubar python
    3
    6
    1943
    Loading More Posts
    • 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.
    • S
      Streakflash last edited by Streakflash

      Hi

      I'm trying to find a way to insert a custom menubar for every TAB of QTabWidget. I just could not find any satisfying soulution! Please help me to figure it out.

      Thank you

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        You can't really add a menu to a tab directly, but there's a workaround. The only assumption is that the content widget of the tab has a layout (no matter what type). Layouts have a setMenuBar() method so you can sneak the menu there like this:

        int numTabs = tabWidget()->count();
        for(int i = 0; i < numTabs; ++i)
           tabWidget->widget(i)->layout()->setMenuBar(yourMenuBar);
        
        1 Reply Last reply Reply Quote 1
        • S
          Streakflash last edited by Streakflash

          @Chris-Kawa omg YES! You are AWESOME! i was cracking my head all day trying to find a solution... Thank you! but Is it possible to realize from QT Designer?

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @Streakflash last edited by

            @Streakflash
            Yeah Chris rocks :)

            You cant do it in designer
            but you can do it in mainwin constructor after setupIU
            it would just be
            ui-> tabWidget->widget

            If you have added it "visually".

            S 1 Reply Last reply Reply Quote 0
            • S
              Streakflash @mrjj last edited by

              @mrjj yeah thats how I'm doing right now, just wanted to know because controlling it from designer would be much comfortable :)

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @Streakflash last edited by

                @Streakflash
                Yeah I agree. But a lot of stuff is not really possible from Designer. Sadly.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post