Skip to content

Commit 952bd27

Browse files
committed
add TreeViean and TreeView2 examples
1 parent 348f010 commit 952bd27

File tree

18 files changed

+569
-1
lines changed

18 files changed

+569
-1
lines changed

Qt.Widgets/CommonControls/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ add_subdirectory(Slider)
2222
add_subdirectory(SpinBox)
2323
add_subdirectory(SpinButton)
2424
add_subdirectory(ToggleButton)
25+
add_subdirectory(TreeView)
26+
add_subdirectory(TreeView2)
2527
add_subdirectory(Widget)

Qt.Widgets/CommonControls/CommonControls.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ SUBDIRS = \
1717
SpinBox \
1818
SpinButton \
1919
ToggleButton \
20+
TreeView \
21+
TreeView2 \
2022
Widget \

Qt.Widgets/CommonControls/ListView/src/ListView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Examples {
1818
layout.addWidget(&listView1, 1);
1919
layout.addWidget(&comboBoxMode, 0);
2020

21+
model.setHorizontalHeaderLabels({"Name", "Type", "Size", "Comment"});
2122
model.appendRow({new QStandardItem(QIcon(QPixmap(aviIcon48)), "First"), new QStandardItem("Movie"), new QStandardItem("5359"), new QStandardItem("This is the first item")});
2223
model.appendRow({new QStandardItem(QIcon(QPixmap(aiIcon48)), "Second"), new QStandardItem("Picture"), new QStandardItem("1256"), new QStandardItem("This is the second item")});
2324
model.appendRow({new QStandardItem(QIcon(QPixmap(bmpIcon48)), "Third"), new QStandardItem("Picture"), new QStandardItem("4284"), new QStandardItem("This is the third item")});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
# Project
4+
project(TreeView)
5+
find_package(Qt5Widgets CONFIG REQUIRED)
6+
7+
# Options
8+
set(CMAKE_AUTOMOC ON)
9+
set(CMAKE_AUTORCC ON)
10+
set(CMAKE_AUTOUIC ON)
11+
set(CMAKE_CXX_STANDARD 17)
12+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
13+
14+
# Application
15+
add_executable(TreeView WIN32 MACOSX_BUNDLE src/TreeView.cpp src/TreeView.h)
16+
target_link_libraries(TreeView Qt5::Widgets)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG += c++17
2+
QT = widgets
3+
SOURCES = src/TreeView.cpp
4+
HEADERS = src/TreeView.h
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* XPM */
2+
static const char* aiIcon16[] = {
3+
/* columns rows colors chars-per-pixel */
4+
"16 16 37 1 ",
5+
" c #1E1E1E",
6+
". c #222222",
7+
"X c #232323",
8+
"o c #252525",
9+
"O c #282828",
10+
"+ c gray18",
11+
"@ c #2F2F2F",
12+
"# c #313131",
13+
"$ c #323232",
14+
"% c gray20",
15+
"& c #343434",
16+
"* c #353535",
17+
"= c gray21",
18+
"- c #373737",
19+
"; c gray22",
20+
": c #393939",
21+
"> c #3A3A3A",
22+
", c gray27",
23+
"< c #494949",
24+
"1 c #4C4C4C",
25+
"2 c gray31",
26+
"3 c #5F5F5F",
27+
"4 c #606060",
28+
"5 c #626262",
29+
"6 c gray39",
30+
"7 c #646464",
31+
"8 c #656565",
32+
"9 c #686868",
33+
"0 c #6A6A6A",
34+
"q c gray49",
35+
"w c #959595",
36+
"e c #9B9B9B",
37+
"r c gray61",
38+
"t c gray63",
39+
"y c gray64",
40+
"u c #A5A5A5",
41+
"i c None",
42+
/* pixels */
43+
"ii*=****-O3iiiii",
44+
"ii*=****;X8eiiii",
45+
"ii*=****;o5yriii",
46+
"ii*=****=#<907ii",
47+
"ii*=*****=#X.oii",
48+
"ii*=******=;:;ii",
49+
"ii*=********=*ii",
50+
"ii*=***==***=*ii",
51+
"ii*=**===***=*ii",
52+
"ii*=*=&%$***=*ii",
53+
"ii*=**=wq6.:=*ii",
54+
"ii*=: 9ut0 >=*ii",
55+
"ii*==@214,#==*ii",
56+
"ii*=*-++o#=*=*ii",
57+
"ii*=**--;=**=*ii",
58+
"ii*=********=*ii"
59+
};
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* XPM */
2+
static const char* aviIcon16[] = {
3+
/* columns rows colors chars-per-pixel */
4+
"16 16 47 1 ",
5+
" c #1E1E1E",
6+
". c gray13",
7+
"X c #222222",
8+
"o c #232323",
9+
"O c #252525",
10+
"+ c gray15",
11+
"@ c #282828",
12+
"# c #2C2C2C",
13+
"$ c #2D2D2D",
14+
"% c gray18",
15+
"& c gray19",
16+
"* c #313131",
17+
"= c #323232",
18+
"- c #343434",
19+
"; c #353535",
20+
": c gray21",
21+
"> c #373737",
22+
", c gray22",
23+
"< c #393939",
24+
"1 c #3A3A3A",
25+
"2 c gray27",
26+
"3 c #494949",
27+
"4 c gray30",
28+
"5 c #4E4E4E",
29+
"6 c #505050",
30+
"7 c #515151",
31+
"8 c #5D5D5D",
32+
"9 c gray37",
33+
"0 c #5F5F5F",
34+
"q c #626262",
35+
"w c #646464",
36+
"e c #656565",
37+
"r c #676767",
38+
"t c #686868",
39+
"y c #6A6A6A",
40+
"u c gray44",
41+
"i c #808080",
42+
"p c #8D8D8D",
43+
"a c gray58",
44+
"s c #959595",
45+
"d c gray59",
46+
"f c #9B9B9B",
47+
"g c gray61",
48+
"h c #A0A0A0",
49+
"j c gray64",
50+
"k c gray66",
51+
"l c None",
52+
/* pixels */
53+
"ll;:;;;;>@0lllll",
54+
"ll;:;;;;,oefllll",
55+
"ll;:;;;;,Oqjglll",
56+
"ll;:;;;;:*3tywll",
57+
"ll;:;;;;;:*oXOll",
58+
"ll;:;;;;;;:,<,ll",
59+
"ll;:;;;;;;;;:;ll",
60+
"ll;:;;::;:;;:;ll",
61+
"ll;:;::;>;;;:;ll",
62+
"ll;:;-=;%-;;:;ll",
63+
"ll;:>&aius8+<;ll",
64+
"ll;<.qkphdr 1;ll",
65+
"ll;>%476952&>;ll",
66+
"ll;::%#$O$*::;ll",
67+
"ll;:;>>>,>:;:;ll",
68+
"ll;:;;;;;;;;:;ll"
69+
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* XPM */
2+
static const char* bmpIcon16[] = {
3+
/* columns rows colors chars-per-pixel */
4+
"16 16 52 1 ",
5+
" c #1B1B1B",
6+
". c #1D1D1D",
7+
"X c #202020",
8+
"o c #222222",
9+
"O c #232323",
10+
"+ c gray14",
11+
"@ c #252525",
12+
"# c #272727",
13+
"$ c #282828",
14+
"% c gray16",
15+
"& c gray17",
16+
"* c #2C2C2C",
17+
"= c #2D2D2D",
18+
"- c gray19",
19+
"; c #313131",
20+
": c #323232",
21+
"> c #343434",
22+
", c #353535",
23+
"< c gray21",
24+
"1 c #373737",
25+
"2 c gray22",
26+
"3 c #393939",
27+
"4 c #3A3A3A",
28+
"5 c #3F3F3F",
29+
"6 c #434343",
30+
"7 c #494949",
31+
"8 c gray32",
32+
"9 c gray33",
33+
"0 c #565656",
34+
"q c gray35",
35+
"w c #5B5B5B",
36+
"e c #5F5F5F",
37+
"r c #626262",
38+
"t c #646464",
39+
"y c #656565",
40+
"u c #686868",
41+
"i c #6A6A6A",
42+
"p c #6C6C6C",
43+
"a c gray54",
44+
"s c gray55",
45+
"d c gray56",
46+
"f c gray59",
47+
"g c gray60",
48+
"h c #9A9A9A",
49+
"j c #9B9B9B",
50+
"k c gray61",
51+
"l c #9F9F9F",
52+
"z c #A2A2A2",
53+
"x c gray64",
54+
"c c #A4A4A4",
55+
"v c #A5A5A5",
56+
"b c None",
57+
/* pixels */
58+
"bb,<,,,,1$ebbbbb",
59+
"bb,<,,,,2Oyjbbbb",
60+
"bb,<,,,,2@rxkbbb",
61+
"bb,<,,,,<;7uitbb",
62+
"bb,<,,,,,<;Oo@bb",
63+
"bb,<,,,,,,<232bb",
64+
"bb,<,,,,,,,,<,bb",
65+
"bb,<,<<<<<<,<,bb",
66+
"bb,<,:,11>:<<,bb",
67+
"bb,<>5>=*25=1,bb",
68+
"bb2+ejfsahguX3bb",
69+
"bb3 ivlcczd0&1bb",
70+
"bb<:6pw89q-#2,bb",
71+
"bb,1;.#&&%11,,bb",
72+
"bb,<<42122<,<,bb",
73+
"bb,<,,,,,,,,<,bb"
74+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <QApplication>
2+
#include "TreeView.h"
3+
4+
using namespace Examples;
5+
6+
int main(int argc, char *argv[]) {
7+
QApplication application(argc, argv);
8+
Window1 window1;
9+
window1.show();
10+
return application.exec();
11+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma once
2+
#include <QComboBox>
3+
#include <QFrame>
4+
#include <QMainWindow>
5+
#include <QStandardItem>
6+
#include <QStandardItemModel>
7+
#include <QHeaderView>
8+
#include <QTreeView>
9+
#include <QVBoxLayout>
10+
#include "Ai16.xpm"
11+
#include "Avi16.xpm"
12+
#include "Bmp16.xpm"
13+
14+
namespace Examples {
15+
class Window1 : public QMainWindow {
16+
Q_OBJECT
17+
public:
18+
Window1() {
19+
layout.addWidget(&treeView1);
20+
21+
auto rootNode = new QStandardItem("Root");
22+
model.appendRow(rootNode);
23+
auto firstNode = new QStandardItem("First");
24+
rootNode->appendRow(firstNode);
25+
firstNode->appendRow(new QStandardItem("Second"));
26+
firstNode->appendRow(new QStandardItem("Third"));
27+
auto fourthNode = new QStandardItem("Fourth");
28+
rootNode->appendRow(fourthNode);
29+
fourthNode->appendRow(new QStandardItem("Fifth"));
30+
fourthNode->appendRow(new QStandardItem("Sixth"));
31+
fourthNode->appendRow(new QStandardItem("Seventh"));
32+
33+
treeView1.setHeaderHidden(true);
34+
treeView1.setModel(&model);
35+
treeView1.expandAll();
36+
37+
setCentralWidget(&frame);
38+
setWindowTitle("Tree view example");
39+
resize(300, 300);
40+
}
41+
42+
private:
43+
QFrame frame;
44+
QVBoxLayout layout {&frame};
45+
QTreeView treeView1;
46+
QStandardItemModel model;;
47+
};
48+
}

0 commit comments

Comments
 (0)