Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicktreeview.cpp File Reference

(01cd43d30e3ca2c4dd94a4a4711604adb9417517)

#include "qquicktreeview_p_p.h"
#include <QtCore/qobject.h>
#include <QtQml/qqmlcontext.h>
#include <QtQuick/private/qquicktaphandler_p.h>
#include <QtQmlModels/private/qqmltreemodeltotablemodel_p_p.h>
#include "moc_qquicktreeview_p.cpp"
Include dependency graph for qquicktreeview.cpp:

Go to the source code of this file.

Variables

static const int kTreeColumn = 0
 \qmlproperty QModelIndex QtQuick::TreeView::rootIndex

Variable Documentation

◆ kTreeColumn

const int kTreeColumn = 0
static

\qmlproperty QModelIndex QtQuick::TreeView::rootIndex

\qmltype TreeView
\inqmlmodule QtQuick
\ingroup qtquick-views
\since 6.3
\inherits TableView
\brief Provides a tree view to display data from a QAbstractItemModel.

A TreeView has a \l model that defines the data to be displayed, and a
\l delegate that defines how the data should be displayed.

TreeView inherits \l TableView. This means that, despite the model
has a parent-child tree structure, TreeView is internally using a
proxy model that converts that structure into a flat table
model that can be rendered by TableView. Each node in the tree ends up
occupying one row in the table, where the first column renders the tree
itself. By indenting each delegate item in that column according to its
parent-child depth in the model, it will end up looking like a tree, even
if it's technically still just a flat list of items.

\section2 Declare a TreeView

TreeView is a data bound control, so it cannot show anything without a
data model. You cannot declare tree nodes in QML.

When you declare a TreeView, you need to specify:

\list
  \li \b{A data model}. TreeView can work with data models that derive from
    \l QAbstractItemModel.
  \li \b{A delegate}. A delegate is a template that specifies how the tree
    nodes are displayed in the UI.
\endlist

\qml
TreeView {

The model needs to be a QAbstractItemModel model: myTreeModel You can set a custom delegate or use a built-in TreeViewDelegate delegate: TreeViewDelegate {} } \endqml

Definition at line 295 of file qquicktreeview.cpp.