TreeViewDelegate QML Type
Import Statement: | import QtQuick.Controls |
Since: | Qt 6.3 |
Inherits: |
プロパティ
- current : bool
- depth : int
- editing : bool
(since 6.5)
- expanded : bool
- hasChildren : bool
- indentation : real
- isTreeNode : bool
- leftMargin : real
- rightMargin : real
- selected : bool
- treeView : TreeView
詳細説明
TreeViewDelegate は、TreeView のdelegate property に割り当てることができるデリゲートです。 アプリケーションのスタイルを使用して、ビュー内のツリーや他の列をレンダリングします。
TreeView { anchors.fill: parent delegate: TreeViewDelegate {} // The model needs to be a QAbstractItemModel // model: yourTreeModel }
TreeViewDelegate はItemDelegate を継承しており、background 、contentItem 、indicator の3つのアイテムで構成されています。 TreeViewDelegate は、ツリー内の位置に応じて、indenting contentItem とインジケータの処理を行います。インジケータは、デリゲートアイテムがtree column の内側にある場合にのみ表示され、モデルアイテムwith children をレンダリングします。
インジケータを変更すると、デフォルトではインデントされなくなります。その代わりに、depth とindentation を考慮して、インジケータのx position を設定することによって、自分でインデントする必要があります。下記はその方法の例です:
TreeViewDelegate { indicator: Item { x: leftMargin + (depth * indentation) } }
contentItemの位置はpadding 。これは、インデントを扱わずにcontentItemを変更できることを意味します。しかし、それはまた、インデントを取り除くことになるので、パディングを他のものに変更することを避けるべきであることを意味します。インジケータの左側のスペースは、代わりにleftMargin で制御されます。インジケータとcontentItemの間のスペースは、spacing 。また、contentItemの右側のスペースはrightMargin 。
ポインタとの対話
TreeViewDelegate はItemDelegate を継承しています。つまり、ユーザーがデリゲートをクリックすると、clicked のようなシグナルを発する。必要であれば、デフォルトの展開/折りたたみ動作に加えて、アプリケーション固有の機能を実装するために、そのシグナルに接続することができます(さらに、デフォルトの動作も無効にするために、pointerNavigationEnabled をfalse
に設定することもできます)。
しかし、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) } } } }
注: ユーザーがデリゲートをクリックしたときに発生するデフォルトの動作(現在のインデックスの変更など)を無効にしたい場合は、pointerNavigationEnabled をfalse
に設定します。
ツリー内のノードの編集
TreeViewDelegate には、デフォルトでedit delegate が割り当てられています。TreeView にedit triggers が設定され、model にediting model items のサポートがある場合、ユーザーはcurrent ツリーノードのテキストを編集するために、いずれかの編集トリガーをアクティブにすることができます。
デフォルトのeditデリゲートは、Qt.EditRole
を使用して、model にデータを読み書きしようとします。QAbstractItemModel::data() がこの役割に対して空の文字列を返した場合、Qt.DisplayRole
が代わりに使用されます。
デフォルトのeditデリゲートが提供する以外のニーズがある場合、TableView.editDelegate に独自のカスタムeditデリゲートを割り当てることができます。
TreeViewも参照して ください。
プロパティ ドキュメント
current : bool |
このプロパティは、デリゲートがselection model のcurrent index を表すかどうかを保持します。
depth : int |
このプロパティは、デリゲートによって描画されるモデルアイテムの深さを保持します。モデル項目の深さは、それがモデル内に持つ祖先の数と同じです。
expanded : bool |
このプロパティは、デリゲートによって描画されたモデル項目がビューで展開されている場合、true
。
hasChildren : bool |
このプロパティは、デリゲートによって描画されたモデルアイテムがモデル内に子アイテムを持つ場合、true
。
indentation : real |
このプロパティは、子がその親に対して水平方向にインデントされるスペースを保持する。
isTreeNode : bool |
このプロパティは、デリゲート項目がツリー内のノードを描画する場合、true
。ツリーの描画に使用されるのはビュー内の 1 つの列のみであるため、その列のデリゲート項目のみがこのプロパティをtrue
に設定します。
ツリー内のノードは、そのdepth
に従ってindented となり、hasChildren がtrue
の場合はindicator を表示します。他の列のデリゲート アイテムは、このプロパティがfalse
に設定されます。
leftMargin : real |
このプロパティは、ビューの左端とインジケータの左端の間のスペースを保持します(インデントに加えて)。インジケータが表示されていない場合、スペースはビューの左端とcontentItemの左端の間になります。
rightMargin 、indentation 、spacingも参照 。
rightMargin : real |
このプロパティは、ビューの右端とcontentItemの右端の間のスペースを保持する。
leftMargin,indentation,spacingも参照 。
selected : bool |
このプロパティは、デリゲートがselection model のselected index を表している場合に保持されます。
© 2025 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.