[Interest] A question about QtQuick.Control 2.0 ComboBox customisation

Nuno Santos nunosantos at imaginando.pt
Tue Sep 27 17:40:21 CEST 2016


Hi,

I’m customising a QtQuick.Control 2.0 ComboBox and I’m facing myself with the following problem:

I don’t know how to close the ComboBox when using a another element than ItemDelegate. The customisation page says the following:

http://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox <http://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox>

delegate: ItemDelegate {
    width: control.width
    text: modelData
    font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal
    highlighted: control.highlightedIndex == index
}

But I need to use a rectangle in order to have a different background color of the combobox drop down, so I’m doing the following:

delegate: Rectangle {
    width: control.width
    height: label.paintedHeight+10
    color: controller.settings.baseColor

    Text {
        id: label
        anchors.fill: parent
        anchors.margins: 10
        text: modelData
        font.family: opensans.name
        font.pixelSize: 14
        verticalAlignment: Text.AlignVCenter
        color: control.highlightedIndex==index?controller.settings.highlightColor:"white"
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            control.currentIndex=index
        }
    }
}

But now, how do I close the combo box? Any ideas?

Regards,

Nuno Santos
Founder / CEO / CTO
www.imaginando.pt
+351 91 621 69 62

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160927/441ac19e/attachment.html>


More information about the Interest mailing list