Qt查找子窗口
2013-11-27 12:25
281 查看
在mfc中最通常的方法是CWnd* GetDlgItem( int nID ) const; 通过能ID获取子窗口;
每个资源都有一个nID作为唯一标识;
在Qt中可以通过 QObject::findChild(const QString & name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const;
T QObject::findChild(const QString & name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option
FindDirectChildrenOnly.
If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.
This example returns a child QPushButton of parentWidget named "button1", even if the button isn't a direct child of the parent:
QPushButton *button = parentWidget->findChild<QPushButton *>("button1");
This example returns a QListWidget child of parentWidget:
QListWidget *list = parentWidget->findChild<QListWidget *>();
This example returns a child QPushButton of parentWidget (its direct parent) named "button1":
QPushButton *button = parentWidget->findChild<QPushButton *>("button1", Qt::FindDirectChildOnly);
This example returns a QListWidget child of parentWidget, its direct parent:
QListWidget *list = parentWidget->findChild<QListWidget *>(QString(), Qt::FindDirectChildOnly);
//
应用:
对于每个继承与QObject的类,都可以setObjectName(const QString & name)设置类的对象名称。
对于控件类,可以直接在“Qt 设计师”中直接获取,修改。
每个资源都有一个nID作为唯一标识;
在Qt中可以通过 QObject::findChild(const QString & name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const;
T QObject::findChild(const QString & name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option
FindDirectChildrenOnly.
If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.
This example returns a child QPushButton of parentWidget named "button1", even if the button isn't a direct child of the parent:
QPushButton *button = parentWidget->findChild<QPushButton *>("button1");
This example returns a QListWidget child of parentWidget:
QListWidget *list = parentWidget->findChild<QListWidget *>();
This example returns a child QPushButton of parentWidget (its direct parent) named "button1":
QPushButton *button = parentWidget->findChild<QPushButton *>("button1", Qt::FindDirectChildOnly);
This example returns a QListWidget child of parentWidget, its direct parent:
QListWidget *list = parentWidget->findChild<QListWidget *>(QString(), Qt::FindDirectChildOnly);
//
应用:
对于每个继承与QObject的类,都可以setObjectName(const QString & name)设置类的对象名称。
对于控件类,可以直接在“Qt 设计师”中直接获取,修改。
相关文章推荐
- QT网上学习资源+查找文档
- winform 查找子窗口
- Qt模块化笔记之Qt Widgets——子区域和子窗口
- QT 遍历目录查找指定文件
- Qt入门(14)——父窗口部件和子窗口部件
- QT:子窗口嵌入到父窗口,子窗口跟随父窗口 qdialog,qwidget
- qt字符串的正则表达式查找
- Qt 对QTextEdit的文本编辑器进行查找操作
- Qt入门(14)——父窗口部件和子窗口部件
- QT如何让子窗口不继承父窗口的边框、背景等风格
- 查找qt生成的exe软件需要的动态库.以及打包
- QT4 在字符串中查找EMAIL地址(转贴增加一个处理方法)
- Qt使用QTextEdit进行文本编辑实现查找高亮
- 开发OpenCV+Qt+C++项目过程中遇到的问题及查找的答案
- Qt::WindowFlags枚举类型(Qt::Widget是独立窗口和子窗口两用的,Qt::Window会有标题栏)
- Qt如何不让父窗口的颜色影响子窗口
- Qt之程序打包(使用windeployqt.exe查找依赖库)
- qt实现子窗口继承父窗口背景图片
- Qt基于对话框---查找
- Qt创建那个XML文档,并且对它实现查找,更新,插入等操作