QWidget: isVisible() == !isHidden() 吗?

判断QWidget是否可见,调用isVisible()还是isHidden()?

在写这篇文章之前,我一直以为是一样的,也就是:

isVisible() == !isHidden()

No!No!No!................

看QT文档对isHidden()的说明:

bool QWidget::isHidden() const

Returns true if the widget is hidden, otherwise returns false.

A hidden widget will only become visible when show() is called on it. It will not be automatically shown when the parent is shown.

To check visibility, use !isVisible() instead (notice the exclamation mark).

isHidden() implies !isVisible(), but a widget can be not visible and not hidden at the same time. This is the case for widgets that are children of widgets that are not visible.

Widgets are hidden if:

  • they were created as independent windows,
  • they were created as children of visible widgets,
  • hide() or setVisible(false) was called.

 首先黑色粗体部分,QT明确了如果要检查控件的可见性,要用isVisible()!

其次红色粗体部分说明了原因,QWidget在某些情况下可能是作为其他控件的子控件,此种情况下,控件的可见性和父控件的可见性有关,也就说,如果父控件不可见,就算子控件自身不是隐藏的,也是不可见的。这时如果还使用isHidden()判断子控件的可见性,就不对了!

所以,没事,多翻翻文档!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值