dh1tw
dh1tw

Reputation: 1491

Propagate Click from QML Combobox

I have a Listmodel where the delegates get selected/highlighted when they are clicked on. However when I click on a Combobox, which is part of the delegate, the delegate does not get selected.

Is there something like propagateComposedEvents which could propagate the click to the MouseArea of the delegate?

What would be the best way to also select the delegate when I click on it's containing Combobox?

Here is a screenshot enter image description here

Here is the example code

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2

ApplicationWindow {
     title: qsTr("Hello World")
     width: 640
     height: 480
     visible: true

    ListModel {
         id: contactsModel
         ListElement {
             name: "Bill Smith"
         }
         ListElement {
             name: "John Brown"
         }
        ListElement {
             name: "Sam Wise"
         }
     }

    ListModel {
         id: roleModel
         ListElement {
             text: "Employee"
         }
         ListElement {
             text: "Manager"
         }
         ListElement {
             text: "Big Boss"
         }
     }

     ListView{
         id: contactsView
         anchors.left: parent.left
         anchors.top: parent.top
         width: parent.width
         height: parent.height
         orientation: Qt.Vertical
         spacing: 10
         model: contactsModel
         delegate: contactsDelegate
     }

     Component{
         id: contactsDelegate
         Rectangle{
             width: 200
             height: 50
             color: ListView.isCurrentItem ? "#003366" : "#585858"
             border.color: "gray"
             border.width: 1

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

             Column{
                 Text {
                     color: "white"
                     text: name
                 }
                 ComboBox{
                     currentIndex: 0
                     model: roleModel
                 }
             }
         }
     }
 }

Upvotes: 2

Views: 3168

Answers (1)

dtech
dtech

Reputation: 49279

ComboBox{
    currentIndex: 0
    model: roleModel
    onPressedChanged: if (pressed) contactsView.currentIndex = index
}

It is not exactly propagating, but it does the trick.

Upvotes: 4

Related Questions