利用ComboButton来做一个下拉的选项

在其它的很多平台上我们可以使用ComboButton来实现我们一个下拉(drop-down)的选项.在Ubuntu.Components 1.3版本中,我们也有类似的东西,虽然在我之前的例程中,我们也实现了一个自己的ComboBox.


我们还是先来看一下一个简单的例子:


Main.qml


import QtQuick 2.4
import Ubuntu.Components 1.3
import Ubuntu.Components.ListItems 1.3

/*!
    \brief MainView with a Label and Button elements.
*/

MainView {
    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "mainView"

    // Note! applicationName needs to match the "name" field of the click manifest
    applicationName: "combobutton.liu-xiao-guo"

    /*
     This property enables the application to change orientation
     when the device is rotated. The default is false.
    */
    //automaticOrientation: true


    width: units.gu(60)
    height: units.gu(85)

    Page {
        title: i18n.tr("combobutton")

        Column {
            anchors.fill: parent
            spacing: units.gu(2)

            ComboButton {
                text: "smaller content"
                Rectangle {
                    height: units.gu(5) // smaller than the default expandedHeight
                    color: "blue"
                }
            }

            ComboButton {
                id: combo
                text: "long scrolled content"

                ListView {
                    model: 10
                    delegate: Standard {
                        text: "Item #" + modelData

                        onClicked: {
                            console.log("item: " + index + " clicked")
                            combo.expanded = false;
                        }

                    }
                }
            }
        }
    }
}

运行我们的例程:

  
从上面可以看出来我们可以在一个drop-down的列表中选择我们所需要的选项.当然,我们也可以更新我们的ComboButton的text的内容.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值