SelectionRectangle QML Type

Used to select table cells inside a TableView . 更多...

import 语句: import QtQuick.Controls 2.2
Since: Qt 6.2
继承: Control

特性

附加特性

详细描述

SelectionRectangle is used for selecting table cells in a TableView . It lets the user start a selection by doing a pointer drag inside the viewport, or by doing a long press on top of a cell.

For a SelectionRectangle to be able to select cells, TableView must have an ItemSelectionModel assigned. The ItemSelectionModel will store any selections done on the model, and can be used for querying which cells that the user has selected.

The following example shows how you can make a SelectionRectangle target a TableView :

    TableView {
        id: tableView
        anchors.fill: parent
        clip: true
        model: TableModel {
            TableModelColumn { display: "name" }
            rows: [ { "name": "Harry" }, { "name": "Hedwig" } ]
        }
        selectionModel: ItemSelectionModel {
            model: tableView.model
        }
        delegate: Rectangle {
            implicitWidth: 100
            implicitHeight: 30
            color: selected ? "blue" : "lightgray"
            required property bool selected
            Text { text: display }
        }
    }
    SelectionRectangle {
        target: tableView
    }
					

注意: A SelectionRectangle itself is not shown as part of a selection. Only the delegates (like topLeftHandle and bottomRightHandle ) are used. You should also consider rendering the TableView delegate as selected .

另请参阅 TableView , TableView::selectionModel ,和 ItemSelectionModel .

特性文档编制

[read-only] active : bool

此特性是 true while the user is performing a selection. The selection will be active from the time the the user starts to select, and until the selection is removed again, for example from tapping inside the viewport.

bottomRightHandle : Component

This property holds the delegate that will be shown on the center of the top-left corner of the selection rectangle. When a handle is provided, the user can drag it to adjust the selection.

把此特性设为 null if you don't want a selection handle on the bottom-right.

另请参阅 topLeftHandle .

[read-only] dragging : bool

此特性是 true whenever the user is doing a pointer drag or a handle drag to adjust the selection rectangle.

selectionMode : enumeration

This property holds when a selection should start.

常量 描述
SelectionRectangle.Drag A selection will start by doing a pointer drag inside the viewport
SelectionRectangle.PressAndHold A selection will start by doing a press and hold on top a cell
SelectionRectangle.Auto SelectionRectangle will choose which mode to use based on the target and the platform. This normally means PressAndHold on touch based platforms, and Drag on desktop. However, Drag will only be used if it doesn't conflict with flicking. This means that TableView will need to be configured with interactive 设为 false , or placed inside a ScrollView (where flicking, by default, is off for mouse events), for Drag to be chosen.

默认值为 Auto .

target : Item

此特性保持 TableView on which the SelectionRectangle should act.

topLeftHandle : Component

This property holds the delegate that will be shown on the center of the top-left corner of the selection rectangle. When a handle is provided, the user can drag it to adjust the selection.

把此特性设为 null if you don't want a selection handle on the top-left.

另请参阅 bottomRightHandle .


附加特性文档编制

SelectionRectangle.control : SelectionRectangle

This attached property holds the SelectionRectangle that manages the delegate instance. It is attached to each handle instance.

SelectionRectangle.dragging : bool

This attached property will be true if the user is dragging on the handle. It is attached to each handle instance.