How do I disable one tab in a QTabWidget?

后端 未结 4 1956
粉色の甜心
粉色の甜心 2021-01-04 05:52

I have a QTabWidget called tabWidget. It has three tabs: \"Basic\", \"Advanced\", and \"Current Structure\". The tabs are displayed in the widget in that order

相关标签:
4条回答
  • 2021-01-04 06:09

    You can't, not this way.

    You have to iterate through all the children in the Page and disable them.

    Something like this:

    QList<QWidget*> list = parentWidget->findChildren<QWidget*>() ;
    foreach( QWidget* w, list ) {
       w->setEnabled( false ) ;
    }
    
    0 讨论(0)
  • 2021-01-04 06:15

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

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

    bool result = false;
    if (result == false)
    {
      tabWidget->setTabEnabled(1, false);
    }
    
    0 讨论(0)
  • 2021-01-04 06:19

    You could disable the layout of the tab.

    bool result = false;
    if (result == false)
    {
      tabWidget->widget(1)->layout()->setDisabled(true);
    }
    
    0 讨论(0)
  • 2021-01-04 06:21

    If you use Qt Widgets Application template and Advanced tab's name is tabAdvanced (you can check the name in Object Inspector), this should work:

    ui->tabAdvanced->setEnabled(false);
    
    0 讨论(0)
提交回复
热议问题