Tumbler QML Type

選択可能なアイテムのホイール。もっと見る...

Import Statement: import QtQuick.Controls
Inherits:

Control

プロパティ

付属物件

方法

  • void positionViewAtIndex(int index, PositionMode mode) (since QtQuick.Controls 2.5 (Qt 5.12))

詳細説明

Tumbler {
    model: 5
    // ...
}

Tumblerは、ユーザーが項目の回転可能な「ホイール」からオプションを選択できるようにします。これは、例えばRadioButton を使うにはオプションが多すぎ、編集可能なSpinBox を使うにはオプションが少なすぎる場合に便利です。キーボードを使う必要がなく、項目数が多いときには両端を折り返すことができるので便利です。

APIは、ListViewPathView のようなビューと似ています。modeldelegate を設定することができ、countcurrentItem プロパティは、ビューに関する情報への読み取り専用アクセスを提供します。ビューを特定のインデックスに配置するには、positionViewAtIndex()を使用します。

しかし、PathViewListView のようなビューとは異なり、(モデルが空でない場合)常に現在のアイテムが存在します。つまり、count0 と等しい場合、currentIndex-1 になります。それ以外の場合は、0 以上になります。

デフォルトでは、モデル内のアイテム数が可視アイテム数より多い限り、Tumblerはwraps 、最上位と最下位に達したとき、つまりcountvisibleItemCount より大きいとき、 になります:

import QtQuick
import QtQuick.Window
import QtQuick.Controls

Rectangle {
    width: frame.implicitWidth + 10
    height: frame.implicitHeight + 10

    function formatText(count, modelData) {
        var data = count === 12 ? modelData + 1 : modelData;
        return data.toString().length < 2 ? "0" + data : data;
    }

    FontMetrics {
        id: fontMetrics
    }

    Component {
        id: delegateComponent

        Label {
            text: formatText(Tumbler.tumbler.count, modelData)
            opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2)
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            font.pixelSize: fontMetrics.font.pixelSize * 1.25
        }
    }

    Frame {
        id: frame
        padding: 0
        anchors.centerIn: parent

        Row {
            id: row

            Tumbler {
                id: hoursTumbler
                model: 12
                delegate: delegateComponent
            }

            Tumbler {
                id: minutesTumbler
                model: 60
                delegate: delegateComponent
            }

            Tumbler {
                id: amPmTumbler
                model: ["AM", "PM"]
                delegate: delegateComponent
            }
        }
    }
}

タンブラーと 入力コントロールのカスタマイズも参照してください

プロパティの説明

count : int [read-only]

このプロパティは、モデル内のアイテムの数を保持する。


currentIndex : int

このプロパティは、現在のアイテムのインデックスを保持する。

このプロパティの値は、count0 と等しい場合は-1 となる。それ以外の場合は、0 以上となる。

currentItem およびpositionViewAtIndex()も参照のこと


currentItem : Item [read-only]

このプロパティは、現在のインデックスの項目を保持する。

currentIndex およびpositionViewAtIndex() も参照して ください。


delegate : Component

このプロパティは、各項目の表示に使用されるデリゲートを保持します。


model : variant

このプロパティは、このタンブラーのデータを提供するモデルを保持する。


moving : bool [since QtQuick.Controls 2.2 (Qt 5.9)]

このプロパティは、ユーザーがタンブラーをドラッグまたはフリックすることによって、タンブラーが現在動いているかどうかを記述します。

このプロパティは QtQuick.Controls 2.2 (Qt 5.9) で導入されました。


visibleItemCount : int

このプロパティは、タンブラーに表示されているアイテムの数を保持します。現在のアイテムは常に垂直中央に配置されるため、奇数でなければなりません。


wrap : bool [since QtQuick.Controls 2.1 (Qt 5.8)]

このプロパティは、タンブラーが上部または下部に達したときに折り返すかどうかを決定します。

デフォルト値は、countvisibleItemCount よりも小さい場合、false です。この動作をオーバーライドするには、このプロパティの値を明示的に設定します。デフォルトの動作に戻すには、このプロパティをundefined に設定します。

このプロパティは、QtQuick.Controls 2.1(Qt 5.8)で導入されました。


Attached Property ドキュメント

Tumbler.displacement : real [read-only]

この Attached プロパティは、-visibleItemCount / 2 からvisibleItemCount / 2 までの値を保持します。この値は、このアイテムが現在のアイテムになるまでの距離を表し、0 は完全に現在のアイテムです。

例えば、以下のアイテムは、カレントアイテムでないときは40%の不透明度で、カレントアイテムになると100%の不透明度に遷移する:

delegate: Text {
    text: modelData
    opacity: 0.4 + Math.max(0, 1 - Math.abs(Tumbler.displacement)) * 0.6
}

Tumbler.tumbler : Tumbler [read-only]

この付属プロパティはタンブラーを保持する。このプロパティはタンブラーデリゲートにアタッチすることができる。アイテムがタンブラーデリゲートでない場合、値はnull である。


メソッドのドキュメント

[since QtQuick.Controls 2.5 (Qt 5.12)] void positionViewAtIndex(int index, PositionMode mode)

mode で指定された位置にindex が来るようにビューを配置します。

例えば

positionViewAtIndex(10, Tumbler.Center)

wrap が真(デフォルト)の場合、PathViewpositionViewAtIndex() 関数で利用可能なモードが利用可能であり、そうでない場合、ListViewpositionViewAtIndex() 関数で利用可能なモードが利用可能である。

注意: wraptrue のときにTumbler.Beginning を使用すると、間違ったアイテムがビューの最上部に配置されるという既知の制限があります。回避策として、index - 1 を渡してください。

このメソッドは QtQuick.Controls 2.5 (Qt 5.12) で導入されました。

currentIndexも参照してください


© 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.