Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-62059

QTabWidget on macOS makes window larger

    XMLWordPrintable

Details

    • macOS

    Description

      Good evening!

      I'm filing a bug about QTabWidget on macOS, again. The previous one was dedicated to ugly styles, the current one is much more funny and strange. Lets say we have a window that contains QTabWidget. We add several tabs and the QTabWidget expands the parent window! In the other words: when I add several tabs, the window that contains the QTabWidget gets resized in order to fit all tab headers. On Windows in the same situation QTabWidget has two buttons with arrows that allow to scroll tabs.

       

      Here is the code:

      MainWindow.h

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <QTabWidget>
      
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();
      
      private:
          Ui::MainWindow *ui;
      
          QTabWidget* tabs;
      
          QAction* actAddTab;
      
      public slots:
          void tabCloseRequested(int idx);
      
          void addNewTab();
      };
      
      #endif // MAINWINDOW_H
      
      

      MainWindow.cpp

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include "qdebug.h"
      
      void MainWindow::tabCloseRequested(int idx) {
          tabs->removeTab(idx);
      }
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow) {
          ui->setupUi(this);
      
          tabs = new QTabWidget();
          tabs->setDocumentMode(true);
          tabs->setMovable(true);
          tabs->setTabsClosable(true);
      
          setCentralWidget(tabs);
      
          connect(tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequested(int)));
      
          tabs->tabBar()->setExpanding(true);
      
      
          actAddTab = new QAction("Add tab");
          connect(actAddTab, SIGNAL(triggered()), this, SLOT(addNewTab()));
      
          auto menu = menuBar()->addMenu("Add tab");
          menu->addAction(actAddTab);
      }
      
      MainWindow::~MainWindow() {
          delete ui;
      }
      
      void MainWindow::addNewTab() {
          tabs->addTab(new QWidget(), QString("New Tab Name %1").arg(tabs->count()));
      }
      
      

      On Windows this code works as expected: we can scroll tab headers, on macOS it expands the window.

       

      I captured a video that demonstrates the issue on macOS. I've also captured a screenshot on Windows which demonstrates the buttons I expect.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.graphics.and.multimedia Qt Graphics Team
            xanx Ivan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes