您的位置:首页 > 编程语言 > Qt开发

QT控件的visible属性

2015-10-21 10:05 197 查看
很多QT的新手设置是老手在使用QT控件的visible属性的时候,很容易犯错。比如show()或者setVisible(true)后,isVisible()应该返回true吧?但其实QT控件的visible属性是一个综合属性:“CallingsetVisible(true) or show() sets the widget to visible status if allits parent widgets up to the window are visible. If an ancestor isnot
visible, the widget won't become visible until all itsancestors are shown. “ 。

在setVisible(true)后:调用 isVisible() 可能返回true或者false;调用 isHidden()一定返回false。

在setVisible(false)后:调用isVisible()返回false;调用isHidden() 返回true。

ps:show()等价于 setVisible(true) 。 hide() 等价于 setVisible(false)。

从我的经验来看,其实大部分时候我们只是想判断控件自己的是否可见flag(也就是假定控件parent可见)。这时候使用isHidden() 来判断比用isVisible()更符合需求,记得要取反。

转自:http://blog.sina.com.cn/s/blog_48d4cf2d0101a8it.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: