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. Aligning QTabBars in Grid Layout
Qt 6.11 is out! See what's new in the release blog

Aligning QTabBars in Grid Layout

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 488 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.
  • D Offline
    D Offline
    Droid07
    wrote on last edited by Droid07
    #1

    For the project I'm working on I'd like to create a layout in which I have three different QTabBars on the sides of a QStackedWidget - The North, West, and East sides. I will use a combination of those selected tabs to determine what widget in the stack will be shown.

    My problem is how I can style these QTabBars. Right now the North bar stretches across the entire StackedWidget, and the East and West TabBars are centered. I want them all to have regular tab sizes and alight in the upper left and upper right corners.

    Any ideas on how I can do that?

    Helper function:

    QTabBar* ProjectTabView::TabGenerator(QTabBar::Shape shape){
        QTabBar* tabBar = new QTabBar();
        tabBar->setShape(shape);
        return tabBar;
    }
    

    Body of code:

        QGridLayout* gridLayout = new QGridLayout();
        this->setLayout(gridLayout);
    
        QTabBar* unitTabs = TabGenerator(QTabBar::RoundedEast);
        unitTabs->addTab("Unit");
        unitTabs->setStyleSheet("QTabBar {border: 1px solid black}");
        QTabBar* subsystemTabs = TabGenerator(QTabBar::RoundedNorth);
        subsystemTabs->addTab("Subsystem");
        QTabBar* logOrStateTabs = TabGenerator(QTabBar::RoundedWest);
        logOrStateTabs->addTab("Log");
    
        QStackedWidget* mainView = new QStackedWidget();
    
        gridLayout->addWidget(subsystemTabs, 0, 1);
        gridLayout->addWidget(logOrStateTabs, 1, 0);
        gridLayout->addWidget(mainView, 1, 1);
        gridLayout->addWidget(unitTabs, 1, 2);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you show a picture of what you would like to achieve ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Droid07
        wrote on last edited by Droid07
        #3

        Ended up figuring this out using Spacers. New Grid code below:

        QGridLayout* gridLayout = new QGridLayout();
        this->setLayout(gridLayout);

        QTabBar* unitTabs = TabGenerator(QTabBar::RoundedEast);
        unitTabs->addTab("Unit");
        QTabBar* subsystemTabs = TabGenerator(QTabBar::RoundedNorth);
        subsystemTabs->addTab("Subsystem");
        QTabBar* logOrStateTabs = TabGenerator(QTabBar::RoundedWest);
        logOrStateTabs->addTab("Log");
        
        QStackedWidget* mainView = new QStackedWidget();
        
        QSpacerItem* leftVertSpacer = new QSpacerItem(1,1,QSizePolicy::Minimum, QSizePolicy::Expanding);
        QSpacerItem* rightVertSpacer = new QSpacerItem(1,1,QSizePolicy::Minimum, QSizePolicy::Expanding);
        QSpacerItem* topHorizSpacer = new QSpacerItem(1,1,QSizePolicy::Expanding, QSizePolicy::Minimum);
        
        gridLayout->addWidget(subsystemTabs, 0, 1);
        gridLayout->addWidget(logOrStateTabs, 1, 0);
        gridLayout->addWidget(mainView, 1, 1, 2, 2);
        gridLayout->addWidget(unitTabs, 1, 3);
        gridLayout->addItem(leftVertSpacer, 2,0);
        gridLayout->addItem(topHorizSpacer, 0,2);
        gridLayout->addItem(rightVertSpacer, 2, 3);
        
        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