Qt 将一个Widget(子)从某个Widget(父)中移除的方法
来源:互联网 发布:l300清零软件 编辑:程序博客网 时间:2024/05/19 23:25
其实很简单,但是对于我来说解决了一个一直困扰我的问题。Qt很多Widget并没有提供delete或者remove的方法。
如果不需要子Widget时,直接delete,用deleteLater()比较好。如果还需要使用子Widget,使用setParent()可以让子Widget从父Widget中剥离出来。无论是直接delete,还是setParent,都会通知父Widget,父Widget都会更新自己的内容。
下面我把英文原文和相关链接附上。
It's not clear to me if you want to preserve the widget and put it somewhere else, or if you want to destroy the widget.
Destroying the widget: If you can get a pointer to the widget, you can simply delete it. The splitter willsafely be notified that its child isbeing deleted and will remove itfrom itself.
Preserving the widget: If you grab the pointer to the widget, you can simply set its parent to some other widget and add it to another widget's layout and it will show up there. This is safe because the QSplitter will be notified that one of its children is being reparented.
If you want to set the parent to NULL (cjhuitt's answer) be aware that you are now responsible for cleaning up that memory because the widget no longer has a parent.
相关链接:http://stackoverflow.com/questions/371599/how-to-remove-qwidgets-from-qsplitter
http://stackoverflow.com/questions/20328437/remove-widget-from-qsplitter
- Qt 将一个Widget(子)从某个Widget(父)中移除的方法
- 从一个widget中打开另一个widget
- Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法
- 将自定义的widget放到Qt Designer中
- QT widget 方法
- 关于QT中对窗口中某个widget建类
- Qt中父子widget的消息传递
- Qt中父子widget的事件传递
- QT中 widget window dialog 的区别
- Qt中父子widget的事件传递
- QT中在子widget中绘制图形
- QT-从QLayout中遍历出组件(Widget)
- 一个简单的widget
- 一个切换的Widget
- Qt中widget大小问题
- JS从一个元素中移除一个子元素
- qt中一个ui中的widget与另一个ui中的dialog之间的交互
- Qt重画widget的背景
- CodeForces 414A Mashmokh and Numbers(模拟)
- ubuntu Security配置初步学习
- 寻找无线的干扰.............
- 表格相对引用和绝对引用及相互切换(复制单元格函数公式保持不变)
- dll 中定义的单例类如何让外部使用
- Qt 将一个Widget(子)从某个Widget(父)中移除的方法
- 清软国际具体要求及事项
- xp jdk7环境下利用webView调用网页android
- Flex做成Map类型
- 高性能HTTP加速器Varnish-3.0.3搭建、配置及优化
- ios指南针小例子
- JQuery常用函数及功能小结
- upstart封装nodejs应用为系统服务
- (未完)字符串模式匹配的几个方法