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

How programically order tabs in QTabWidget?



  • I try

    void TabWindow::keyReleaseEvent(QKeyEvent *event)
    {
        if (event->key()==Qt::Key_Control)
        {
            std::cout <<  "release" << std::endl;
            CodeEditor *current = qobject_cast<CodeEditor *>(tabWidget->currentWidget());
            tabWidget->removeTab(tabWidget->currentIndex());
            tabWidget->insertTab(0, current, current->name);
            tabWidget->setCurrentWidget(current);
        }
    }
    

    But is probably bad, because:

    void QLayout::removeWidget(QWidget *widget)
    {
        int i = 0;
        QLayoutItem *child;
        while ((child = itemAt(i))) {
            if (child->widget() == widget) {
                delete takeAt(i);
                invalidate();
            } else {
                ++i;
            }
        }
    }
    

    It is impossible change order of tabs?



  • But in Qt Creator is this solved - Tab when Control is pressed show list


  • Lifetime Qt Champion

    Hi
    From code you could use
    https://doc.qt.io/qt-5/qtabbar.html#moveTab
    via
    tabwidget->tabBar()


Log in to reply