SelectionRectangle QML Type
TableView 内のテーブルセルを選択するために使用されます。詳細...
| Import Statement: | import QtQuick.Controls |
| Since: | Qt 6.2 |
| Inherits: |
プロパティ
- active : bool
- bottomRightHandle : Component
- dragging : bool
- selectionMode : enumeration
- target : Item
- topLeftHandle : Component
関連するプロパティ
詳細説明

SelectionRectangleは、TableView 内のテーブルセルを選択するために使用されます。これにより、ユーザーはビューポート内でポインタをドラッグするか、セルの上で長押しすることで、選択を開始できます。
SelectionRectangleがセルを選択できるようにするには、TableView にItemSelectionModel が割り当てられている必要があります。ItemSelectionModel は、モデル上で行われたすべての選択情報を保存し、ユーザーがどのセルを選択したかを照会するために使用できます。
以下の例は、SelectionRectangleのターゲットとしてTableView を設定する方法を示しています:
TableView {
id: tableView
anchors.fill: parent
clip: true
acceptedButtons: Qt.NoButton // mouse-drag changes selection
model: TableModel {
TableModelColumn { display: "name" }
TableModelColumn { display: "age" }
rows: [ { "name": "Harry", "age": "11" },
{ "name": "Hedwig", "age": "8" } ]
}
selectionModel: ItemSelectionModel {
model: tableView.model
}
delegate: TableViewDelegate { padding: 2 }
}
SelectionRectangle {
target: tableView
}注:Selection Rectangle 自体は選択範囲の一部として表示されません。topLeftHandle やbottomRightHandle といったデリゲートのみが使用されます。また、rendering the TableView delegate as selected の使用も検討してください。
TableView 、TableView::selectionModel 、およびItemSelectionModelも参照してください 。
プロパティのドキュメント
active : bool [read-only]
このプロパティは、ユーザーが選択操作を行っている間、true となります。選択状態は、ユーザーが選択を開始した時点から、例えばビューポート内をタップするなどして選択が解除されるまで有効です。
bottomRightHandle : Component
このプロパティには、選択矩形の左上隅の中央に表示されるデリゲートが格納されます。ハンドルが指定されている場合、ユーザーはそれをドラッグして選択範囲を調整できます。
選択が解除された際、ハンドルはデフォルトでは非表示になりません。代わりに、カスタムフェードアウトアニメーションを実装するためには、これをデリゲートの役割とします。ハンドルを確実に非表示にする最も簡単な方法は、`visible ` を `SelectionRectangle` の `active ` 状態にバインドすることです:
SelectionRectangle {
bottomRightHandle: Rectangle {
width: 20
height: 20
visible: SelectionRectangle.control.active
}
}右下に選択ハンドルを表示したくない場合は、このプロパティを `null ` に設定してください。
「topLeftHandle」も参照してください 。
dragging : bool [read-only]
ユーザーが選択矩形を調整するためにポインタやハンドルをドラッグしている間、このプロパティは `true ` になります。
selectionMode : enumeration
このプロパティは、選択範囲の開始位置を指定する際に有効です。
| 定数 | 説明 |
|---|---|
SelectionRectangle.Drag | ビューポート内でポインタをドラッグすることで、選択が開始されます |
SelectionRectangle.PressAndHold | セル上でボタンを長押しすると、選択が開始されます。 |
SelectionRectangle.Auto | SelectionRectangle は、target および使用中の入力デバイスに基づいて、使用するモードを選択します。通常、マウスを使用する場合はDrag 、タッチスクリーンを使用する場合はPressAndHold となります。 ただし、Drag はフリッキングと競合しない場合にのみ使用されます。競合を回避する1つの方法は、acceptedButtons をQt.NoButton に設定して、マウスドラッグによるフリッキングを無効にすることです。その場合、マウスホイールやタッチパッドのスクロールジェスチャーは引き続き機能し、タッチスクリーンのフリッキングも機能し続け、タッチスクリーンでの選択は長押しで開始できます。 もう一つの方法は、interactive をfalse に設定することです。これにより、フリッキングとスクロールが完全に無効化されます(おそらくこれは、UI内の特定のモードにおいて一時的にのみ行うべきでしょう)。さらに別の方法として、TableView をScrollView 内に配置する方法があります( 内では、デフォルトでマウスイベントに対するフリッキングは無効になっています)。 |
デフォルト値は `Auto` です。
target : Item
このプロパティは、SelectionRectangle が処理対象とするTableView を保持します。
topLeftHandle : Component
このプロパティには、選択矩形の左上隅の中央に表示されるデリゲートが格納されます。ハンドルが指定されている場合、ユーザーはそれをドラッグして選択範囲を調整できます。
選択が解除された際、ハンドルはデフォルトでは非表示になりません。代わりに、カスタムフェードアウトアニメーションを実現するために、これを処理するのはデリゲートの役割となります。ハンドルを確実に非表示にする最も簡単な方法は、単に `visible ` を `SelectionRectangle` の `active ` 状態にバインドすることです。
SelectionRectangle {
topLeftHandle: Rectangle {
width: 20
height: 20
visible: SelectionRectangle.control.active
}
}左上に選択ハンドルを表示したくない場合は、このプロパティを `null ` に設定してください。
「bottomRightHandle」も参照してください 。
添付のプロパティのドキュメント
SelectionRectangle.control : SelectionRectangle [attached]
このアタッチされたプロパティには、デリゲートインスタンスを管理するSelectionRectangle が格納されています。これは各ハンドルインスタンスにアタッチされています。
SelectionRectangle.dragging : bool [attached]
ユーザーがハンドルをドラッグしている場合、このアタッチされたプロパティは `true ` になります。これは各ハンドルインスタンスにアタッチされています。
© 2026 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.