how to hide the horizontalLayout? QT 隐藏布局Layout中的控件

文章介绍了如何在QT中隐藏布局(horizontalLayout),方法是创建包含布局和其他控件的QWidget,设置其可见性为false,或者遍历并隐藏布局的所有子控件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    how to hide the horizontalLayout?

QT 隐藏布局Layout中的控件

===============================

how to hide the horizontalLayout?

TheBadger 2015年12月7日 13:28

A layout can not be hidden since they are not widgets and does not have a setVisible() function.

You have to create a widget that you can hide, that contains the layout and the other widgets that should be hidden, then you hide the widget instead of the layout.

QWidget* myWidget = new QWidget();
QHBoxLayout * layout = new QHBoxLayout(myWidget);
layout->addWidget(new QLabel("Label"));
myWidget->setVisible(false);

QT 隐藏布局Layout中的控件

隐藏整个布局控件

先获取所有子控件,然后隐藏

    for (int i = 0; i < ui->horizontalLayout->count(); ++i) {
        QWidget* w = ui->horizontalLayout->itemAt(i)->widget();
        if (w != NULL)
            w->setVisible(false);
    }

  https://blog.csdn.net/wangmingshi666/article/details/122216764

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值