当前位置: 代码迷 >> QT开发 >> QML 遇到的有关问题希望大神路过解答
  详细解决方案

QML 遇到的有关问题希望大神路过解答

热度:544   发布时间:2016-04-25 02:58:25.0
QML 遇到的问题希望大神路过解答
QML中使用ComboBox时,下拉框的风格怎么设置? 还有就是下拉框的高度怎么设置,当我添加的项过多时就会超出整个界面的高度,很是苦恼啊
------解决思路----------------------
引用:
Quote: 引用:

去 www.qt.io去咨询吧,里面好多知识可以用到实际当中来




我去看了,有点眼花缭乱的,您能具体点吗? 怎么找用到这个控件的例子

import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
Item{
    ComboBox {
        id: box
        currentIndex: 2
        width: 100
        height: 20
        anchors.centerIn: parent
        activeFocusOnPress: true
        style: ComboBoxStyle {
            id: comboBox
            background: Rectangle {
                id: rectCategory
                radius: 2
                border.width: 1
                color: "#fff"
            }
            label: Text {
                verticalAlignment: Text.AlignVCenter
                horizontalAlignment: Text.AlignHCenter
                font.pointSize: 10
                font.family: "微软雅黑"
                font.capitalization: Font.SmallCaps
                color: "black"
                text: control.currentText
            }
            // drop-down customization here
            property Component __dropDownStyle: MenuStyle {
                __maxPopupHeight: 200
                __menuItemType: "comboboxitem"

                frame: Rectangle {              // background
                    color: "#00ffffff"
                    border.width: 0
                    radius: 0
                }

                itemDelegate.label:Text {
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                    font.pointSize: 12
                    font.family: "微软雅黑"
                    font.capitalization: Font.SmallCaps
                    color: styleData.selected ? "white" : "black"
                    text: styleData.text
                }

                itemDelegate.background: Rectangle {  // selection of an item
                    radius: 0
                    color: styleData.selected ? "darkGray" : "transparent"
                }

                __scrollerStyle: ScrollViewStyle { }
            }
        }

        model: ListModel {
            id: cbItems
            ListElement { text: "香蕉" }
            ListElement { text: "苹果" }
            ListElement { text: "椰子" }
            ListElement { text: "橘子" }
            ListElement { text: "葡萄" }
        }
    }
}
  相关解决方案