qt creator 中的"提升为..."功能简介
2024-08-25 10:26:47
1.新建一个项目
2.打开文件:mainwindow.ui ->拖一个 tree widget 控件到画布->右击弹出对话框->单击"提升为..."选项
3.输入 MyTree->点击"添加"按钮
4.点击"提升"按钮
5.新建继承自 QTreeWidget 类的新类 MyTree
6.文件结构:
7.文件内容:
// mytree.h
#ifndef MYTREE_H
#define MYTREE_H #include <QTreeWidget> class MyTree : public QTreeWidget
{
public:
MyTree(QWidget *parent=);
void test();
}; #endif // MYTREE_H
// mytree.cpp
#include "mytree.h" #include <QMessageBox> MyTree::MyTree(QWidget *parent):
QTreeWidget(parent)
{ }
void MyTree::test(){
QMessageBox::warning(, "test", "test");
}
#include "mainwindow.h"
#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->treeWidget->test();
} MainWindow::~MainWindow()
{
delete ui;
}
8.ui_mainwindow.h 中的代码变成了 new MyTree, 这样可以深度封装 tree 类, 无需类型转换
// ui_mainwindow.h
treeWidget = new MyTree(centralWidget);
最新文章
- MVC 之 T4模板简介
- 【转载】PHP 开发者该知道的 5 个 Composer 小技巧
- python算法——第四天
- 文件I/O(不带缓冲)之open函数
- 类名.class与类名.this详解
- String.format Tutorial
- Windows Live Writer 完成开源并推出开源分支
- AngularJS的工作原理
- Apache Rewrite 中文详解
- jquery写的树状列表插件-alvintree
- Linux shell 基础
- [UOJ UR #4追击圣诞老人]
- 记一次非常规方法对接硬件设备(Grason Stadler GSI 61)
- c_数据结构_队的实现
- [Dababase - MySQL- Linux] 数据库安装位置
- 6.3 基于二分搜索树、链表的实现的集合Set复杂度分析
- 『TensorFlow』使用集合collection控制variables
- windows 脚本
- Getting started with Processing 示例11-9 追随鼠标移动
- Using the G711 standard