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

QTabBar scrolls back to beginning automatically on tab text update



  • I have a QTabWidget with many tabs, so the scroll buttons appear on the right side of the tab bar.

    3e07fe7b-cbdc-4512-8de3-b9589f683e58-image.png

    The tab titles get updated from time to time. Whenever any of the tab titles gets updated, the scroll jumps automatically to the beginning. Sometimes the updates are pretty frequent so it gets kind of hard to click a tab on the right end.

    Is there a way of preventing the automatic scroll to the left when a tab text gets updated?

    You can check this behavior by creating a new QWidget-based project on Qt. Drop a QTabWidget on the form and use the following code to auto-update the title of the first tab:

    Widget::Widget(QWidget* parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
        for (int i = 1; i < 20; ++i) {
            ui->tabWidget->addTab(new QWidget(this), QString("Tab %1").arg(i));
        }
    
        auto timer = new QTimer(this);
    
        connect(timer, &QTimer::timeout, [=]() {
            static int i = 0;
            i++;
            ui->tabWidget->setTabText(0, QString("Tab %1").arg(i));
        });
    
        timer->start(1000);
    }
    

    Thanks in advance.


  • Qt Champions 2019

    I vaguely remember such a bug in the bug tracker but think it was closed already - what Qt version do you use?



  • @Christian-Ehrlicher I use 5.9.4. I'm afraid I cannot upgrade to any other version for now.


  • Qt Champions 2019

    See https://bugreports.qt.io/browse/QTBUG-27084 - it worked for me with 5.111 so I closed the issue.


Log in to reply