Hiding the TabWidget
-
Here a basic example:
//header of your class, you need at least a QString and a QWidget pointer as member variables { ..... private: QWidget *removedWidget = Q_NULLPTR; QString removedTabString; }
//cpp part of your class, this creates a QTabwidget, populates it with 3 tabs, and uses remove and addTab to move the first tab to the end QTabWidget *tWidget = new QTabWidget(this); tWidget->show(); tWidget->addTab(new QWidget(), "Tab1"); tWidget->addTab(new QWidget(), "Tab2"); tWidget->addTab(new QWidget(), "Tab3"); //The following lines will take Tab1, remove it/store it and add it back to the tabwidget at the last position //remove Tab and 'save' it in a member variable, its not really saved, but you store a pointer to it if(removedWidget == Q_NULLPTR){ //Pointer is empty tab can be "stored" //Save Tab text removedTabString = tWidget->tabText(0); //'Save' actual widget removedWidget = tWidget->widget(0); //Remove from QTabWidget tWidget->removeTab(0); } //Add Tab to widget if( removedWidget != Q_NULLPTR){ //The pointer actually points to a valid previously removed tab tWidget->addTab(removedWidget, removedTabString); //set pointer back to 0 to free it for potential next operation removedWidget = Q_NULLPTR; }
-
@JonB !
no, it's not like that people only see the tab name but after clicking he will see inside anything just like visual studio example.
I want to make my code for mention image. Where I will make 2 black round image when I will click this it will pop out.
.
Last I need to get 2nd one type output -
Hi
What is not working ?
How does your current code look ? -
Hi
So you have 2 tabwidgets?
Since its impossible to click on hidden tab as its not there. so you could never unhide it again with clicking.So when user click on tab 1 on tabWidget1, you want tab 1 to be shown on tabwidget 2?
else i dont get what you are trying as the tab will be COMPLETELY gone if u "hide" it and hence you cannot click on it again
so some other means of showing it is needed.Or did you just use @J-Hilk code as it is and got a second widget as it does
QTabWidget *tWidget = new QTabWidget(this);
??
If you are using that code with UI then
QTabWidget *tWidget = ui->yourtabwidget as else you will create a second one. -
@amarism
so you want to hide what INSIDE the tab and not the actual tab?I dont know how Visual studio tabs works.
But in Qt the tab is the whole white area and it will always show regardless of what you put inside.But if you just want to hide the content of the tab, why you ask how to remove / insert tabs.
It sounds like u just want to hide ListWidget or what you have inside and not the "Tab 1" -
@amarism said in Hiding the TabWidget:
when hiding the Tab widget next we can't show hiding tab
Im not sure what that means. If you hide tabWidget, all tabs will be hidden.
-
@mrjj I have 2 tab widget tab (tab1 and tab2), Initially, I want to show only the tab just like minimize format (closed inside the black box)
and when i will click on the Tab 1 it will show the whole content of the tab (maximize the tab content). just like below image
and again we click the same tab it will again minimize it(toggle). -
Hi
Ah. i see.
The issues that the tabs lives inside the tabwidget.
so if you reduce the size of the tabwidget to appear "collapsed" then all must be collapsed
at same time. if thats ok, you can alter the width of the widget.Alternatively, you could use
http://doc.qt.io/qt-5/qtabbar.html#details
which might work better for your use case.