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);

最新文章

  1. MVC 之 T4模板简介
  2. 【转载】PHP 开发者该知道的 5 个 Composer 小技巧
  3. python算法——第四天
  4. 文件I/O(不带缓冲)之open函数
  5. 类名.class与类名.this详解
  6. String.format Tutorial
  7. Windows Live Writer 完成开源并推出开源分支
  8. AngularJS的工作原理
  9. Apache Rewrite 中文详解
  10. jquery写的树状列表插件-alvintree
  11. Linux shell 基础
  12. [UOJ UR #4追击圣诞老人]
  13. 记一次非常规方法对接硬件设备(Grason Stadler GSI 61)
  14. c_数据结构_队的实现
  15. [Dababase - MySQL- Linux] 数据库安装位置
  16. 6.3 基于二分搜索树、链表的实现的集合Set复杂度分析
  17. 『TensorFlow』使用集合collection控制variables
  18. windows 脚本
  19. Getting started with Processing 示例11-9 追随鼠标移动
  20. Using the G711 standard

热门文章

  1. JavaWeb之原生数据库连接
  2. 记vue API 知识点
  3. BLE抓包是怎么回事儿?
  4. Linux的编码及编码转换
  5. css div 细边框
  6. h5拖拽上传图片
  7. 通过WebSocket实现一个简单的聊天室功能
  8. python的range()函数
  9. 通过渲染改变tabBarItem的背景图片
  10. icon图标和文字整体居中在button按钮