Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show/Hide sub-tab on QTabWidget

Tags:

c++

qt

qtabwidget

Assuming I have a QTabWidget that contains 5 sub-tabs. Now I want to show/hide a sub-tab in one of 5 sub-tabs by following code

ui->twListTabs->widget(0)->hide();           // Hide first sub-tab

But this didn’t work for me. Do you have any solutions?

Thanks!

like image 585
Tan Viet Avatar asked Aug 23 '13 04:08

Tan Viet


1 Answers

You only have the option to use:

void QTabWidget::removeTab(int index)

You need to store the pointer to the QWidget in the tab so that you can later insert it.

You could e.g. do something like:

class TabWidget : public QTabWidget
{
    Q_OBJECT          
    enum tabwidgets {tabwidget1,tabwidget2,...,number_of_tabwidgets};
    QWidget* widgets_[number_of_tabwidgets];
public:
    TabWidget(QWidget* parent = 0) : QWidget(parent)
    {
        for(int i(0); i < number_of_tabwidgets; ++i)
        {
            switch(i)
            {
            case tabwidget1:
                insertTab(i,widgets_[i] = new TabWidget1,QString::number(i));
                ....
            }
        }
    }
};
like image 177
user2672165 Avatar answered Oct 06 '22 22:10

user2672165