当前位置:网站首页>Qtreewidget control of QT
Qtreewidget control of QT
2022-07-25 22:41:00 【Things turn at will】
One 、QTreeWidget Use
Adding tree nodes
#include "QtWidgetsApplication1.h"
#include <QtWidgets/QApplication>
#include <QTreeWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QtWidgetsApplication1 w;
//w.show();
QTreeWidget* tree = new QTreeWidget();
// Add a level one node
QTreeWidgetItem *items1 = new QTreeWidgetItem(tree,
QStringList(QString("num_1")));
QTreeWidgetItem *items2 = new QTreeWidgetItem(tree,
QStringList(QString("num_2")));
QTreeWidgetItem *items3 = new QTreeWidgetItem(tree,
QStringList(QString("num_3")));
// Add secondary nodes
QTreeWidgetItem *item104 = new QTreeWidgetItem(items3,
QStringList(QString("item104")));
QTreeWidgetItem *item145 = new QTreeWidgetItem(item104,
QStringList(QString("item145")));
tree->show();
return a.exec();
}Realization effect

Two 、 Delete node
tree->takeTopLevelItem(1);// Delete index as 1 The node of
// lookup And num_1 Completely consistent items , And back to .
QList<QTreeWidgetItem*> list = tree->findItems("num_1", Qt::MatchFlag::MatchExactly);
// Delete this item
for (auto item : list) {
delete item;
}
3、 ... and 、 Custom style
#include "QtWidgetsApplication1.h"
#include <QtWidgets/QApplication>
#include <QTreeWidget>
#pragma execution_character_set("utf-8")
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QtWidgetsApplication1 w;
//w.show()
QStringList head;
head << " full name ";
QTreeWidget* tree = new QTreeWidget();
tree->show();
// Set the header
tree->setHeaderLabels(head);
// Add a level one node
head.clear();
head << " Wang Genji ";
QTreeWidgetItem *items1 = new QTreeWidgetItem(tree, head);
head.clear();
head << " Li dachui ";
QTreeWidgetItem *items3 = new QTreeWidgetItem(tree, head);
/// Set the background color
items3->setBackground(0, QBrush(Qt::green));
head.clear();
head << " Lisiji ( Non biological )";
QTreeWidgetItem *item104 = new QTreeWidgetItem(items3, head);
return a.exec();
}
Reference resources :
QT MSVC Chinese compilation error error: C2001: Line breaks in constants _ The blog of Yuanyue villa -CSDN Blog _qt Chinese compilation error
QTreeWidget Qt The most commonly used and best used tree list form _louie_chen The blog of -CSDN Blog _qt Tree list
边栏推荐
- Binder原理
- [training Day12] tree! Tree! Tree! [greed] [minimum spanning tree]
- [training Day12] be go! [dynamic programming] [mathematics]
- Data type conversion
- 数据质量:数据治理的核心
- [training day15] paint road [minimum spanning tree]
- 软件测试 pytest pytest的命名规则 用例的前后置 conftest.py 定制allure报告 @pytest.mark.parametrize()装饰器作数据驱动
- Five constraints and three paradigms
- Document flow definition, box model related knowledge
- Force deduction solution summary 919 complete binary tree inserter
猜你喜欢

Xiaobai programmer's sixth day

ThreadLocal summary (to be continued)

3 词法分析

Binder原理

冯诺依曼体系结构

面试题 17.11. 单词距离 ●●

新媒体运营策略(以小红书为例)帮助你快速掌握爆款创作方法

Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture

Google analyzes how UA can be transferred to the latest version of GA4

【MySQL提权】UDF提权(附带大马)
随机推荐
Qt5.12 installation error prompt: c:\qt5.12.11\vcredist\vcredist_ msvc2019_ x86.exe /norestart /q
Box model (2)
Build commercial projects based on ruoyi framework
Multi data source switching
【数据库学习】Redis 解析器&&单线程&&模型
软件测试 pytest pytest的命名规则 用例的前后置 conftest.py 定制allure报告 @pytest.mark.parametrize()装饰器作数据驱动
数据平台下的数据治理
If it is modified according to the name of the framework module
BIO、NIO、AIO的区别?
【集训DAY15】油漆道路【最小生成树】
JD quick navigation box
【MySQL提权】UDF提权(附带大马)
【集训DAY12】Bee GO!【动态规划】【数学】
Data quality: the core of data governance
Array中可以用泛型吗
Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)
Xiaobai programmer's fifth day
Can generic types be used in array
3 lexical analysis
[training day15] good name [hash]