Search code examples
qtqmlqtquickcontrols

Combobox doesn't open popup if MouseArea is above it


I have a listview with a delegate that has MouseArea covering the whole of a delegate. In that MouseArea's onClick slot I specifically set

mouse.accepted = false

but the Combobox from QtQuick.Controls 1.4 that lives in that delegate still refuses to open its popup on clicks. I've tested that combobox should receive the click with:

ComboBox {
                id: cbChapters
                model: chapters
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        mouse.accepted = false
                        console.log("arrived")
                    }
                }
            }

And the click events do arrive into this inner mouse area, just not into the combobox itself it seems... what might be the problem?


Solution

  • Answering my own question: Problem seems to be that MouseArea automatically accepts Pressed events and in the Combobox code itself there's this:

    onPressed: {
        if (!Settings.hasTouchScreen)
            popup.toggleShow()
    }
    onClicked: {
        if (Settings.hasTouchScreen)
            popup.toggleShow()
    }
    

    So it seems like Clicked requires touchscreen to open the popup(which is not present on the desktop, obviously) This leaves only Pressed to open the popup, but it's being suppressed at the uppermost MouseArea as it is not a composed event and propagateComposedEvents does nothing for it.

    The solution could be :

    1) to go through your mouse area chain and in each one of them set:

    onPressed: {
    mouse.accepted = false
    }
    

    2) call popup directly in "clicked" handler

    ComboBox {
    id: cbChapters
    MouseArea {
        anchors.fill: parent
        propagateComposedEvents: true
        onClicked: {
            cbChapters.__popup.toggleShow()
        }
    }
    }