Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to control TabBar width in MdiSubwindow



  • I would like to title text in tabbed view mode of MDI subwindow to adjust to text length. Currently, it is too wide.



  • You can get hold of the underlying tabbar and call setExpanding(false) on it, see the "documentation":http://doc.qt.nokia.com/latest/qtabbar.html#expanding-prop

    The following example illustrates how this can be done:

    @

    #include <QtGui>
    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    QMainWindow window;

    QMdiArea *area = new QMdiArea(&window);
    area->setViewMode(QMdiArea::TabbedView);
    QMdiSubWindow *first = area->addSubWindow(new QLineEdit(area));
    first->setWindowTitle("First");
    QMdiSubWindow *second = area->addSubWindow(new QLineEdit(area));
    second->setWindowTitle("Second");
    window.setCentralWidget(area);
    
    QList<QTabBar *> tabBarList = area->findChildren<QTabBar*>();
    QTabBar *tabBar = tabBarList.at(0);
    if (tabBar) {
     tabBar->setExpanding(false);
    

    }
    window.show();
    return app.exec();
    }
    @
    Does this give you the result you are looking for?



  • I found that tabBar is accessible. However, visual result did not change after expanding() is set to false.



  • When running the example I pasted above, do the tabs adjust to the length of the text? If so, can you modify the example so that it shows your problem? Which version of Qt are you using and on which platform?


Log in to reply