TreeViewDelegate QML类型

TreeViewDelegate QML Type

TreeViewDelegate QML类型

A delegate that can be assigned to a TreeViewMore...

​可以分配给TreeView的委托。详细信息。。。

Import Statement:

导入语句:

import QtQuick.Controls

Since:

自:

Qt 6.3

Inherits:

继承:

ItemDelegate

Properties

属性

Detailed Description

详细描述

A TreeViewDelegate is a delegate that can be assigned to the delegate property of a TreeView. It renders the tree, as well as the other columns, in the view using the application style.

​TreeViewDelegate是可以分配给TreeView的委托属性的委托。它使用应用程序样式渲染视图中的树以及其他列。

TreeView {
    anchors.fill: parent
    delegate: TreeViewDelegate {}
    // The model needs to be a QAbstractItemModel
    // model: yourTreeModel
}

TreeViewDelegate inherits ItemDelegate, which means that it's composed of three items: a background, a contentItem, and an indicator. TreeViewDelegate takes care of indenting the contentItem and the indicator according their location in the tree. The indicator will only be visible if the delegate item is inside the tree column, and renders a model item with children.

​TreeViewDelegate继承了ItemDelegates,这意味着它由三项组成:背景、内容项和指示器。TreeViewDelegate负责根据contentItem和指示器在树中的位置缩进它们。只有当委托项位于树列内并呈现具有子项的模型项时,该指示器才可见。

If you change the indicator, it will no longer be indented by default. Instead you need to indent it yourself by setting the x position of the indicator, taking the depth and indentation into account. Below is an example of how to do that:

​如果更改指示器,默认情况下它将不再缩进。相反,您需要通过设置指示器的x位置来自己缩进,同时考虑深度和缩进。下面是如何做到这一点的示例:

TreeViewDelegate {
    indicator: Item {
        x: leftMargin + (depth * indentation)
    }
}

The position of the contentItem is controlled with padding. This means that you can change the contentItem without dealing with indentation. But it also means that you should avoid changing padding to something else, as that will remove the indentation. The space to the left of the indicator is instead controlled with leftMargin. The space between the indicator and the contentItem is controlled with spacing. And the space to the right of the contentItem is controlled with rightMargin.

​contentItem的位置由padding控制。这意味着您可以在不处理缩进的情况下更改contentItem。但这也意味着您应该避免将填充更改为其他内容,因为这样会删除缩进。指示器左侧的空格由leftMargin控制。指示器和contentItem之间的间距由spacing控制。contentItem右侧的空间由rightMargin控制。

Interacting with pointers

与指针交互

TreeViewDelegate inherits ItemDelegate. This means that it will emit signals such as clicked when the user clicks on the delegate. If needed, you could connect to that signal to implement application specific functionality, in addition to the default expand/collapse behavior (and even set pointerNavigationEnabled to false, to disable the default behavior as well).

​TreeViewDelegate继承ItemDelegate。这意味着当用户单击委托时,它将发出单击等信号。如果需要,除了默认的展开/折叠行为(甚至将pointerNavigationEnabled设置为false,以禁用默认行为)之外,还可以连接到该信号以实现特定于应用程序的功能。

But the ItemDelegate API does not give you information about the position of the click, or which modifiers are being held. If this is needed, a better approach would be to use pointer handlers, for example:

​但ItemDelegate API不会提供有关单击位置的信息,也不会提供正在使用哪些修饰符的信息。如果需要,更好的方法是使用指针处理器,例如:

TreeView {
    id: treeView
    delegate: TreeViewDelegate {
        TapHandler {
            acceptedButtons: Qt.RightButton
            onTapped: someContextMenu.open()
        }

        TapHandler {
            acceptedModifiers: Qt.ControlModifier
            onTapped: {
                if (treeView.isExpanded(row))
                    treeView.collapseRecursively(row)
                else
                    treeView.expandRecursively(row)
            }
        }
    }
}

See also TreeView.

​请参见TreeView。

Property Documentation

属性文档

current : bool

This property holds if the delegate represent the current index in the selection model.

​则此属性表示委托是否选择模型中的当前索引。

depth : int

This property holds the depth of the model item drawn by the delegate. The depth of a model item is the same as the number of ancestors it has in the model.

此属性保存委托绘制的模型项的深度。模型项的深度与它在模型中的祖先数量相同。

expanded : bool

This property is true if the model item drawn by the delegate is expanded in the view.

如果委托绘制的模型项在视图中展开,则此属性为true。

hasChildren : bool

This property is true if the model item drawn by the delegate has children in the model.

如果委托绘制的模型项在模型中有子项,则此属性为true。

indentation : real

This property holds the space a child is indented horizontally relative to its parent.

此属性保留子级相对于其父级水平缩进的空间。

isTreeNode : bool

This property is true if the delegate item draws a node in the tree. Only one column in the view will be used to to draw the tree, and therefore, only delegate items in that column will have this property set to true.

如果委托项在树中绘制节点,则此属性为true。视图中只有一列用于绘制树,因此,只有该列中的委托项将此属性设置为true。

A node in the tree is indented according to its depth, and show an indicator if hasChildren is true. Delegate items in other columns will have this property set to false.

​树中的节点根据深度缩进,如果hasChildren为true,则显示一个指示符。其他列中的委托项将此属性设置为false。

leftMargin : real

This property holds the space between the left edge of the view and the left edge of the indicator (in addition to indentation). If no indicator is visible, the space will be between the left edge of the view and the left edge of the contentItem.

此属性保留视图左边缘和指示器左边缘之间的空间(除了缩进)。如果没有可见的指示器,则空间将位于视图的左边缘和contentItem的左边缘之间。

See also rightMarginindentation, and spacing.

​另请参见右边距、缩进和间距。​

rightMargin : real

This property holds the space between the right edge of the view and the right edge of the contentItem.

此属性保留视图右边缘和contentItem右边缘之间的空间。

See also leftMarginindentation, and spacing.

​另请参见左边距、缩进和间距。

selected : bool

This property holds if the delegate represent a selected index in the selection model.

​此属性表示委托选择模型中的选定索引,则此属性保持不变。

treeView : TreeView

This property points to the TreeView that contains the delegate item.

​此属性指向包含委托项的TreeView。

© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值