mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-05 08:45:25 +08:00
qt 6.5.1 original
This commit is contained in:
@ -0,0 +1,11 @@
|
||||
TARGET = mv_tree
|
||||
TEMPLATE = app
|
||||
QT += widgets
|
||||
requires(qtConfig(treeview))
|
||||
SOURCES += main.cpp \
|
||||
mainwindow.cpp
|
||||
HEADERS += mainwindow.h
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/modelview/6_treeview
|
||||
INSTALLS += target
|
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(mv_tree LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tutorials/modelview/6_treeview")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(mv_tree
|
||||
main.cpp
|
||||
mainwindow.cpp mainwindow.h
|
||||
)
|
||||
|
||||
set_target_properties(mv_tree PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(mv_tree PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS mv_tree
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
13
examples/widgets/tutorials/modelview/6_treeview/main.cpp
Normal file
13
examples/widgets/tutorials/modelview/6_treeview/main.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
//! [Quoting ModelView Tutorial]
|
||||
// modelview.cpp
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStandardItem>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, treeView(new QTreeView(this))
|
||||
, standardModel(new QStandardItemModel(this))
|
||||
{
|
||||
setCentralWidget(treeView);
|
||||
|
||||
QList<QStandardItem *> preparedRow = prepareRow("first", "second", "third");
|
||||
QStandardItem *item = standardModel->invisibleRootItem();
|
||||
// adding a row to the invisible root item produces a root element
|
||||
item->appendRow(preparedRow);
|
||||
|
||||
QList<QStandardItem *> secondRow = prepareRow("111", "222", "333");
|
||||
// adding a row to an item starts a subtree
|
||||
preparedRow.first()->appendRow(secondRow);
|
||||
|
||||
treeView->setModel(standardModel);
|
||||
treeView->expandAll();
|
||||
}
|
||||
|
||||
QList<QStandardItem *> MainWindow::prepareRow(const QString &first,
|
||||
const QString &second,
|
||||
const QString &third) const
|
||||
{
|
||||
return {new QStandardItem(first),
|
||||
new QStandardItem(second),
|
||||
new QStandardItem(third)};
|
||||
}
|
||||
//! [Quoting ModelView Tutorial]
|
31
examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
Normal file
31
examples/widgets/tutorials/modelview/6_treeview/mainwindow.h
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTreeView; // forward declarations
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
QList<QStandardItem *> prepareRow(const QString &first,
|
||||
const QString &second,
|
||||
const QString &third) const;
|
||||
|
||||
QTreeView *treeView;
|
||||
QStandardItemModel *standardModel;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
Reference in New Issue
Block a user