1

I have just this simple qml application, that should output background color, when is clicked. Actually it still outputs undefined.

import QtQuick 2.1
import QtQuick.Controls 1.0

ApplicationWindow {
    title: qsTr("Hello World")
    width: 1400
    height: 800
    color: "#414141"

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {console.log(parent.color)}
    }
}
Krab
  • 6,526
  • 6
  • 41
  • 78

1 Answers1

2

I am not sure exactly why but it looks like ApplicationWindow is not directly the parent of your MouseArea. You can check this by adding an id to your ApplicationWindow like root and then changing your onClicked event to this

onClicked: {
  console.log("MouseArea parent is: ", parent);
  console.log("root is: ", root);
}

I get this in the output which shows two different items

MouseArea parent is:  QQuickItem(0x101d369b0)
root is:  ApplicationWindow_QMLTYPE_7(0x101d35460)

To avoid this, just use console.log(root.color) instead of using parent

koopajah
  • 23,792
  • 9
  • 78
  • 104
  • yes you are right, output is different, but actually now if i change parent to id value, then settings new color has no effect (nothings happened after root.color = "#414141") – Krab Feb 14 '14 at 19:10
  • @Krab > I noticed that the color changes as soon as you "move" the Window which must force an update or something. You might want to report a bug. In the meantime you could put a `Rectangle` filling the whole parent and change its color? – koopajah Feb 14 '14 at 19:15
  • yeah it works now if i add root.update() after color change. I don't know if this is bug, maybe i must call it, thx anyway. – Krab Feb 14 '14 at 19:22