当前位置: 首页 > news >正文

Qt 将一个Widget(子)从某个Widget(父)中移除的方法

        其实很简单,但是对于我来说解决了一个一直困扰我的问题。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


相关文章:

  • Bloglink list
  • 函数返回值:引用类型和非引用类型
  • C语言表达式和表达式的值
  • C语言知识点考题
  • 判断一个数是否为2的幂次
  • C99标准的新特性
  • C/C++标准资料
  • 如果我再次被面试,我会问的几个问题
  • Linux 常用命令记录
  • C++关键字
  • Open Broadcaster Software源码阅读笔记
  • 简单算法--迭代/递归
  • 背包九讲笔记
  • 关于类成员函数中静态变量的一点提示
  • C++ 强制类型转换若干问题
  • 【知识碎片】第三方登录弹窗效果
  • co模块的前端实现
  • HTTP那些事
  • IDEA常用插件整理
  • Java 23种设计模式 之单例模式 7种实现方式
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • JS实现简单的MVC模式开发小游戏
  • LeetCode541. Reverse String II -- 按步长反转字符串
  • Lucene解析 - 基本概念
  • python_bomb----数据类型总结
  • rabbitmq延迟消息示例
  • RedisSerializer之JdkSerializationRedisSerializer分析
  • vue--为什么data属性必须是一个函数
  • 基于Dubbo+ZooKeeper的分布式服务的实现
  • 前端设计模式
  • 前端相关框架总和
  • 适配mpvue平台的的微信小程序日历组件mpvue-calendar
  • 网页视频流m3u8/ts视频下载
  • 一个项目push到多个远程Git仓库
  •  一套莫尔斯电报听写、翻译系统
  • !!【OpenCV学习】计算两幅图像的重叠区域
  • # 20155222 2016-2017-2 《Java程序设计》第5周学习总结
  • #define
  • #设计模式#4.6 Flyweight(享元) 对象结构型模式
  • #我与Java虚拟机的故事#连载01:人在JVM,身不由己
  • (04)Hive的相关概念——order by 、sort by、distribute by 、cluster by
  • (4)Elastix图像配准:3D图像
  • (android 地图实战开发)3 在地图上显示当前位置和自定义银行位置
  • (done) 两个矩阵 “相似” 是什么意思?
  • (html转换)StringEscapeUtils类的转义与反转义方法
  • (附源码)springboot 校园学生兼职系统 毕业设计 742122
  • (官网安装) 基于CentOS 7安装MangoDB和MangoDB Shell
  • (算法)求1到1亿间的质数或素数
  • (原創) 物件導向與老子思想 (OO)
  • (转)EOS中账户、钱包和密钥的关系
  • (转)IOS中获取各种文件的目录路径的方法
  • .bat文件调用java类的main方法
  • .NET Core WebAPI中封装Swagger配置
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .NET 使用 XPath 来读写 XML 文件