[SOLVED] Hide and show a QTabWidget tab

  • How can I set a QTabWidget tab to hidden and after some signal show the same tab again.

    I've tried already to delete it, but couldn't get an object instance copy to add it later.

    Any hint?


  • Welcome to Qt DevNet.

    Have you tried tabWidget->tabBar()->hide() ?

  • Yes, I tried already. But did not work.

  • I'm not sure if was it's clear, but I want to hide and show a specific tab, not the whole tabBar.

  • Are you talking about something like this
    void Widget::on_pushButton_clicked()
    if (m_hiddenWidget) {
    ui->tabWidget->insertTab(m_hiddenIndex, m_hiddenWidget, m_hiddenLabel);
    m_hiddenWidget = nullptr;
    } else {
    m_hiddenWidget = ui->tabWidget->currentWidget();
    m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
    m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);

  • Thank you for the response, but, I think it won't work in my case because into the tab I have a set of widgets which must to be hidden/showed too.

    These tabs were designed using QtCreator and not initialized along with my code, then I do not insert a new tab from my code as it was created before, I thought it would be a matter of setting it as hidden or visible, but it is not looking like so simple.

  • In my example I created QTabWidget in Qt designer.
    Each tab in the QTabWidget is a QWidget that contains other widgets.
    In my example m_hiddenWidget is a QWidget and it keeps all widgets that are in the current widget like edit lines and the labels.
    At the begging m_hiddenWidget is nullptr I use it to keep the content of a hidden tab between remove and insert.

  • Ok, I'll try this. When finish it I'll tell you the status.

    Thanks again.

  • Thank you so much! It worked.

  • @andreycI am not understood. whats m_hiddenWidget,m_hiddenIndex and m_hiddenLabel

  • @andreyc It work very well, thank you so much.

Log in to reply