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. QTabBar and dynamic setTabButton
Qt 6.11 is out! See what's new in the release blog

QTabBar and dynamic setTabButton

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • L Offline
    L Offline
    Lachrymology
    wrote on last edited by
    #1

    Hi all,

    I have a problem with the following function: QTabBar::setTabButton

    The function itself can receive a QWidget.

    I've used my own derived QWidget, which contains two QPushButtons which have a fixed width.

    Theses two buttons are changing their visibility during runtime.

    My problem is, that the tab width doesn't adjust its size dynamically to the new width of the widget.
    I tried to overwrite the sizeHint of the derived widget, which didn't had any effect. At least I used setFixedWidth for the widget. Furthermore I used QTabBar::repaint

    The tab itself doesn't shrink or grow based on the new width of the widget - ONLY the text of the tab is moved based on the widget size.

    If I resize the entire window for 1 pixel all tabs are receiving their correct size based on their widgets.

    Does anyone have a clue how to force the QTabBar to paint the tabs like the entire window was resized?

    Best regards,
    Mike

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lachrymology
      wrote on last edited by
      #2

      Hi all,

      after a bit trial and error I discovered three dirty work-a-rounds.

      I think the not executed "d->layoutTabs();" is responsible for this behaviour:

      void QTabBar::resizeEvent(QResizeEvent *)
      {
          Q_D(QTabBar);
          if (d->layoutDirty)
              updateGeometry();
          d->layoutTabs();
      
          d->makeVisible(d->currentIndex);
      }
      

      The first work-a-round is to resize the tabBar two times:

          this->tabBar()->resize(this->tabBar()->size() + QSize(1, 1));
          this->tabBar()->resize(this->tabBar()->size() - QSize(1, 1));
      

      Another way would be to set the same icon size again to set the layoutDirty=true:

      this->tabBar()->setIconSize( this->tabBar()->iconSize() );
      

      The problem with this is, that the tabBar jumps to the beginning of the available tabs and doesn't stay at the selected tab.

      The third and maybe best work-a-round is the following:

          if( this->count() > 0 )
              this->tabBar()->setTabText( 0, this->tabBar()->tabText( 0 ) );
      

      Any other ideas are appreciated.

      Best regards,
      Mike

      raven-worxR 1 Reply Last reply
      0
      • L Lachrymology

        Hi all,

        after a bit trial and error I discovered three dirty work-a-rounds.

        I think the not executed "d->layoutTabs();" is responsible for this behaviour:

        void QTabBar::resizeEvent(QResizeEvent *)
        {
            Q_D(QTabBar);
            if (d->layoutDirty)
                updateGeometry();
            d->layoutTabs();
        
            d->makeVisible(d->currentIndex);
        }
        

        The first work-a-round is to resize the tabBar two times:

            this->tabBar()->resize(this->tabBar()->size() + QSize(1, 1));
            this->tabBar()->resize(this->tabBar()->size() - QSize(1, 1));
        

        Another way would be to set the same icon size again to set the layoutDirty=true:

        this->tabBar()->setIconSize( this->tabBar()->iconSize() );
        

        The problem with this is, that the tabBar jumps to the beginning of the available tabs and doesn't stay at the selected tab.

        The third and maybe best work-a-round is the following:

            if( this->count() > 0 )
                this->tabBar()->setTabText( 0, this->tabBar()->tabText( 0 ) );
        

        Any other ideas are appreciated.

        Best regards,
        Mike

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @Lachrymology
        try:

        QEvent e(QEvent::FontChange);
        QCoreApplication::sendEvent( tabBar, &e );
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • L Offline
          L Offline
          Lachrymology
          wrote on last edited by
          #4

          @raven-worx
          Thanks for your work-a-round. It's quite simple and smooth.

          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