qtabwidget tab隐藏_显示/隐藏QTabWidget上的子选项卡

在Qt编程中,遇到无法直接隐藏QTabWidget子标签的问题。常规方法不起作用,如`ui->twListTabs->widget(0)->hide();`。解决方法是通过自定义TabWidget类,存储子标签指针,并使用`removeTab`方法来实现子标签的隐藏与插入。具体实现包括创建一个枚举以标识各个子标签,并在构造函数中插入并存储子标签。
摘要由CSDN通过智能技术生成

Assuming I have a QTabWidget that contains 5 sub-tabs. Now I want to show/hide a sub-tab in one of 5 sub-tabs by following code

ui->twListTabs->widget(0)->hide(); // Hide first sub-tab

But this didn’t work for me. Do you have any solutions?

Thanks!

解决方案

You only have the option to use:

void QTabWidget::removeTab(int index)

You need to store the pointer to the QWidget in the tab so that you can later insert it.

You could e.g. do something like:

class TabWidget : public QTabWidget

{

Q_OBJECT

enum tabwidgets {tabwidget1,tabwidget2,...,number_of_tabwidgets};

QWidget* widgets_[number_of_tabwidgets];

public:

TabWidget(QWidget* parent = 0) : QWidget(parent)

{

for(int i(0); i < number_of_tabwidgets; ++i)

{

switch(i)

{

case tabwidget1:

insertTab(i,widgets_[i] = new TabWidget1,QString::number(i));

....

}

}

}

};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值