如何禁用QTabWidget中的一个选项卡? [英] How do I disable one tab in a QTabWidget?
问题描述
我有一个名为tabWidget的QTabWidget
.它具有三个选项卡:基本",高级"和当前结构".这些选项卡按此顺序显示在窗口小部件中.
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.
每当布尔值result
为false时,我都想禁用高级"选项卡.我认为这将像下面的代码一样简单:
I want to disable the "Advanced" tab whenever 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 when I check it:
tabWidget->tabBar()->isTabEnabled(1); // This returns true
为什么该选项卡没有被禁用?还有另一种方法吗?
Why doesn't the tab become disabled? Is there another way to do it?
我正在使用Qt 5.4.0.
I am using Qt 5.4.0.
推荐答案
您可以使用成员函数根据您的代码段,它看起来像这样:
Based on your code snippet, it would look like this:
bool result = false;
if (result == false)
{
tabWidget->setTabEnabled(1, false);
}
这篇关于如何禁用QTabWidget中的一个选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!