How to disable one tab in QTabWidget?

I have a QTabWidget called tabWidget. It has three tabs: Basic, Advanced, and Current Structure. Tabs are displayed in widgets in this order.

I want to disable the Advanced tab when the Boolean result is false. I thought it would be as simple as this code:

 bool result = false; if (result == false) { tabWidget->widget(1)->setDisabled(true); } 

Unfortunately, this code does not disable the tab, it remains enabled even if I check it:

 tabWidget->tabBar()->isTabEnabled(1); // This returns true 

Why is the tab not disabled? Is there any other way to do this?

I am using Qt 5.4.0.

+6
source share
3 answers

You can enable / disable individual tabs in a QTabWidget using the setTabEnabled member function (int index, bool enable) .

Based on your code snippet, it will look like this:

 bool result = false; if (result == false) { tabWidget->setTabEnabled(1, false); } 
+17
source

You cannot, not like that.

You need to iterate all the children on the page and disable them.

Something like that:

 QList<QWidget*> list = parentWidget->findChildren<QWidget*>() ; foreach( QWidget* w, list ) { w->setEnabled( false ) ; } 
+1
source

You can disable tab layout.

 bool result = false; if (result == false) { tabWidget->widget(1)->layout()->setDisabled(true); } 
0
source

Source: https://habr.com/ru/post/985377/


All Articles