[SOLVED] Hide and show a QTabWidget tab
-
wrote on 17 Oct 2014, 14:20 last edited by
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?
Thanks!
-
wrote on 17 Oct 2014, 15:01 last edited by
Welcome to Qt DevNet.
Have you tried tabWidget->tabBar()->hide() ?
-
wrote on 17 Oct 2014, 16:07 last edited by
Yes, I tried already. But did not work.
-
wrote on 17 Oct 2014, 16:10 last edited by
I'm not sure if was it's clear, but I want to hide and show a specific tab, not the whole tabBar.
-
wrote on 17 Oct 2014, 17:52 last edited by
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;
ui->pushButton->setText("Hide");
} else {
m_hiddenWidget = ui->tabWidget->currentWidget();
m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);
ui->tabWidget->removeTab(m_hiddenIndex);
ui->pushButton->setText("Show");
}
}
@ -
wrote on 17 Oct 2014, 18:42 last edited by
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.
-
wrote on 17 Oct 2014, 18:52 last edited by
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. -
wrote on 17 Oct 2014, 19:13 last edited by
Ok, I'll try this. When finish it I'll tell you the status.
Thanks again.
-
wrote on 17 Oct 2014, 19:28 last edited by
Thank you so much! It worked.
-
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;
ui->pushButton->setText("Hide");
} else {
m_hiddenWidget = ui->tabWidget->currentWidget();
m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);
ui->tabWidget->removeTab(m_hiddenIndex);
ui->pushButton->setText("Show");
}
}
@wrote on 18 May 2018, 07:23 last edited by@andreycI am not understood. whats m_hiddenWidget,m_hiddenIndex and m_hiddenLabel
-
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;
ui->pushButton->setText("Hide");
} else {
m_hiddenWidget = ui->tabWidget->currentWidget();
m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);
ui->tabWidget->removeTab(m_hiddenIndex);
ui->pushButton->setText("Show");
}
}
@wrote on 4 Mar 2019, 06:50 last edited by@andreyc It work very well, thank you so much.