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. QTabWidget size
Qt 6.11 is out! See what's new in the release blog

QTabWidget size

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

    Hello,

    I have a QTabWidget with only 3 tabs and I would like that those tabs take the space of the lenght of the widget: Now I have :

    TTT
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX

    And I would like

    xxxTxxxTxxxTxxx
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX
    XXXXXXXXXXXXX

    I know that I could do this with stylesheets for a given qtabwidget size but I dont know how I could do that it fits automatically if the qtabwidget size changes.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      Hi,

      after the tabwidget's stylesheet is loaded and applied you need to resize the tabbar in your code: I think you could do this in two ways, either by subclassing the QTabWidget and manipulate the tab bar inside(recommended) or as following:

      @ QTabBar tabBar = ui->tabWidget->findChild<QTabBar >(QLatin1String("qt_tabwidget_tabbar"));
      if(tabBar)
      {
      QPushButton
      button = new QPushButton();
      button->setFlat(true);
      button->setFixedWidth(200);
      button->setText(tabBar->tabText(0));
      tabBar->setTabText(0,"");
      tabBar->setTabButton(0, QTabBar::LeftSide,((QWidget
      )(button)));
      }@

      getting the tabbar in such way looks "unorthodox" but it works :)

      Cheers!

      1 Reply Last reply
      0
      • BlackMambaB Offline
        BlackMambaB Offline
        BlackMamba
        wrote on last edited by
        #3

        I wil try this out, thanks :)

        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