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 depending on current Tab

QTabWidget size depending on current Tab

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

    I have the same problem with the https://stackoverflow.com/questions/29128936/qtabwidget-size-depending-on-current-tab, so I tried Nejat's answer,

    PreferenceWidget::PreferenceWidget(QWidget* parent) : QWidget(parent)
    {
        setWindowTitle(tr("Preference"));
        setFixedWidth(600);
    
        m_tabWidget = new QTabWidget(this);
        connect(m_tabWidget, &QTabWidget::currentChanged, this, &PreferenceWidget::updateSizes);
        m_tabWidget->addTab(createGeneralWidget(), tr("General"));
        m_tabWidget->addTab(createBehaviorWidget(), tr("Behavior"));
    
        QHBoxLayout* hLayout = new QHBoxLayout(this);
        hLayout->addWidget(m_tabWidget);
    }
    
    void PreferenceWidget::updateSizes(int index)
    {
        for (int i = 0; i < m_tabWidget->count(); ++i)
        {
            if (i != index)
            {
                m_tabWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
            }
        }
    
        m_tabWidget->widget(index)->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
        m_tabWidget->widget(index)->resize(m_tabWidget->widget(index)->minimumSizeHint());
        m_tabWidget->widget(index)->adjustSize();
        resize(minimumSizeHint());
        adjustSize();
    }
    

    But it didn't work. What's wrong?

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

      Hi,

      What version of Qt are you using ?
      On what OS ?
      Can you provide the full class so people can test it ?

      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

      • Login

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