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. How to manipulate layout of QTabBar?
Forum Updated to NodeBB v4.3 + New Features

How to manipulate layout of QTabBar?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 721 Views 2 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    Hi! I am trying to create a widget in QTabBar of a QTabWidget. To achieve this I created a few widgets inside QWidget and added it to my QTabBar like this:

    tabBar = ui.tabWidget->tabBar();
    newTabBar = new myTabBar; // QWidget with multiple widgets inside it
    tabBar->setTabButton(0, QTabBar::LeftSide, newTabBar);
    

    I was able to add the widgets, but I am not able to control the margins of QTabBar. It looks like this:

    TabProblem.PNG
    No matter how many different methods I try, I am unable to get rid of the extra margins around the widgets in the tab bar. I want the tab bar to be the exact size of the widget that I am putting in there. I tried the following methods (comments above describes what the end result was):

    /* Doesn't do anything */
    tabBar = ui.tabWidget->tabBar();
    tabBar->setContentsMargins(0, 0, 0, 0);
    newTabBar = new myTabBar;
    tabBar->setTabButton(0, QTabBar::LeftSide, newTabBar);
    
    /* Throws an exception: 0x00007FF9F06F4B1A (Qt5Widgetsd.dll) in QtWidgetsApplication1.exe: 0xC0000005: Access violation reading location 0x0000000000000008. */
    tabBar = ui.tabWidget->tabBar();
    tabBar->layout()->setContentsMargins(0, 0, 0, 0);
    newTabBar = new myTabBar;
    tabBar->setTabButton(0, QTabBar::LeftSide, newTabBar);
    
    /* This produces a weird result shown in picture below.*/
    tabBar = ui.tabWidget->tabBar();
    newTabBar = new myTabBar;
    myLayout = new QVBoxLayout;
    myLayout->addWidget(newTabBar);
    myLayout->setContentsMargins(0, 0, 0, 0);
    tabBar->setLayout(myLayout);
    

    TabWeird.PNG

    Is there any way I can get rid of this extra margin?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I dont think you can.
      https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtabbar.cpp.html
      seems to be no layouts we can adjust.

      Also if you could, it would no longer be possible to switch tab as you cant click on the actual tab anymore :)

      CJhaC 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        I dont think you can.
        https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtabbar.cpp.html
        seems to be no layouts we can adjust.

        Also if you could, it would no longer be possible to switch tab as you cant click on the actual tab anymore :)

        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on last edited by
        #3

        @mrjj Thanks! It's a pity that we can't change the layout of the Tab Bar.

        mrjjM 1 Reply Last reply
        0
        • CJhaC CJha

          @mrjj Thanks! It's a pity that we can't change the layout of the Tab Bar.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @CJha
          Hi
          You could use a QStacked instead and make your own header bar for the full widgets.

          1 Reply Last reply
          1

          • Login

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