网站备案域名用二级域名,青岛seo全网营销,网站页面制作公司,亳州网站建设公司1. 介绍
Tumbler是一个用于创建旋转选择器的组件。它提供了一种直观的方式来让用户从一组选项中进行选择#xff0c;类似于转盘式数字密码锁。网上找的类似网图如下#xff1a; 在QML里#xff0c;这种组件一共有两个版本#xff0c;分别在QtQuick.Extras 1.4(旧)和QtQuic…1. 介绍
Tumbler是一个用于创建旋转选择器的组件。它提供了一种直观的方式来让用户从一组选项中进行选择类似于转盘式数字密码锁。网上找的类似网图如下 在QML里这种组件一共有两个版本分别在QtQuick.Extras 1.4(旧)和QtQuick.Controls 2.15(新)里。
2.QtQuick.Extras 1.4版本
Tumbler控件需要与一个或多个TumblerColumn项一起使用它们定义了每个列的内容。 TumblerColumn的model属性保存本列的数据模型。 也可以使用带有角色的模型
ListModel {id: listModelListElement {foo: A1bar: B1baz: C1}ListElement {foo: A2bar: B2baz: C2}ListElement {foo: A3bar: B3baz: C3}}Tumbler {anchors.centerIn: parentTumblerColumn {model: listModelrole: foo}TumblerColumn {model: listModelrole: bar}TumblerColumn {model: listModelrole: baz}}我们还可以自定义它的样式定义整个Tumbler外观可以使用TumblerStyle定义单列外观的就使用TumblerColumn的delegate和highlight属性。这版有很多bug就不演示了。
3.QtQuick.Controls 2.15版本
Component {id: cusDelgateText {text: modelDataopacity: 0.8horizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenterfont.pixelSize: 16}}Row {id: row_layanchors.fill: parentTumbler {id: hoursTumblermodel: 12delegate: cusDelgatevisibleItemCount: 3 // 可见项数wrap: false // 是否环绕(循环展示内容)}Tumbler {id: minutesTumblermodel: 60delegate: cusDelgate}Tumbler {id: amPmTumblermodel: [AM, PM]delegate: cusDelgate}}结果展示 自定义Tumbler:
Tumbler {id: controlmodel: 15background: Item {Rectangle {opacity: control.enabled ? 0.2 : 0.1border.color: #000000width: parent.widthheight: 1anchors.top: parent.top}Rectangle {opacity: control.enabled ? 0.2 : 0.1border.color: #000000width: parent.widthheight: 1anchors.bottom: parent.bottom}}delegate: Text {text: qsTr(Item %1).arg(modelData 1)font: control.fonthorizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenteropacity: 1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)}Rectangle {anchors.horizontalCenter: control.horizontalCentery: control.height * 0.4width: 40height: 1color: #21be2b}Rectangle {anchors.horizontalCenter: control.horizontalCentery: control.height * 0.6width: 40height: 1color: #21be2b}}结果展示