Congratulations to our 2022 Qt Champions!

Detect Clicks outside QML Window

  • How do i detect clicks outside Window {} in QML ?

    @Rectangle {
    id: topLevel

    height: 400; width: 400

    Window {
    id: windowObj

      color: "blue"
      height: 200; width: 200
      onActiveChanged { console.trace() }


    Component.onCompleted: windowObj.visible = true

    Suppose I click on some part of *topLevel *outside windowObj.
    onActiveChanged works on Windows but not on MAC.

    {Using: QtQuick 2.1, QtQuick.Window 2.1, QML/Qt 5.2.0}

  • Lifetime Qt Champion


    Can you try the latest Qt version to check whether this behavior still occurs ?

  • have Qt 5.3.0 on Mac. Does not work. 1 thing i should mention is that the documentation does not mention onActiveChanged for QML Window {} element. It is just that QWindow has it and hence available to QML as well.

    <1> What could be the issue/solution (or maybe there is some other way to do it)

    <2> Actually I am trying to make my own combobox. The DropDown is a Window {} with flag as Qt.Popup (or Qt.SplashScreen which produces less flickering when in full screen mode) which i need to close moment the user clicks anywhere outside it and hence i need to capture such a signal. Do you know of a better way to make such a drop down?

Log in to reply