TableViewDelegate QML Type
Import Statement: | import QtQuick.Controls |
Since: | Qt 6.9 |
Inherits: |
属性
详细说明
TableViewTableViewDelegate 是一个可分配给delegate property 的委托。它使用应用程序样式渲染视图中表格的每个单元格。
TableView { anchors.fill: parent delegate: TableViewDelegate {} // model: yourModel }
TableViewDelegate 继承于ItemDelegate ,这意味着它由两个项目组成:background 和contentItem 。
contentItem 的位置由padding 控制。
与指针交互
TableViewDelegate 继承于ItemDelegate 。这意味着当用户点击委托时,它将发出clicked 等信号。您可以连接该信号来实现特定于应用程序的功能。
但是,ItemDelegate API 不会向您提供有关点击位置的信息,也不会向您提供所持有的修改器的信息。如果需要这些信息,更好的方法是使用指针处理程序等:
TableView { id: tableView delegate: TableViewDelegate { TapHandler { acceptedButtons: Qt.RightButton onTapped: someContextMenu.open() } TapHandler { acceptedModifiers: Qt.ControlModifier onTapped: tableView.doSomethingToCell(row, column) } } }
注: 如果要禁用用户点击委托时发生的默认行为(如更改当前索引),可将pointerNavigationEnabled 设置为false
。
编辑表格中的单元格
TableViewDelegate 已分配了默认的edit delegate 。如果TableView 设置了edit triggers ,而model 又支持editing model items ,那么用户就可以激活任何一个编辑触发器来编辑current 表格单元格的文本。
默认编辑委托将使用Qt.EditRole
来读取和写入model 的数据。如果您需要使用其他角色,或有默认编辑委托以外的需求,您可以随时为TableView.editDelegate 分配自己的委托。
另请参阅 自定义 TableViewDelegate和TableView 。
属性文档
current : bool |
该属性表示委托是否代表selection model 中的current index 。
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.