
 Originally Posted by 
laszlo.gosztola
					 
				 
				I removed the parent property from the MessageBox, but it stayed relative to the item
			
		 
	 
 QML is a declarative language. If you declare one item within the scope of another, it will be its child.
I don't know why you're so reluctant to create the element just when you need it. Especially that you're trying to use it in imperative manner anyway.
Added after 23 minutes:
Here is a crude but working example of a completely declarative way of approaching the problem:
	
	- import QtQuick 1.0 
-   
-   
-   
- Rectangle { 
-     id: rectangle1 
-     width: 360 
-     height: 360 
-   
-     function showBox() { 
- 	messagebox.state = "shown" 
-     } 
-   
-     Rectangle { 
- 	// some button 
-   
- 	width: 100 
- 	height: 50 
- 	color: 'red' 
- 	anchors.left: parent.left 
- 	anchors.leftMargin: 5 
- 	anchors.top: parent.top 
- 	anchors.topMargin: 5 
- 	MouseArea { 
- 	    anchors.fill: parent 
- 	    onClicked: showBox() 
- 	} 
-     } 
-   
-     Rectangle { 
- 	id: messagebox 
- 	anchors.fill: parent 
- 	color: '#dd000000' 
- 	opacity: 0 
- 	z: 1000 
- 	Rectangle { // box 
- 	    width: 200 
- 	    height: 100 
- 	    radius: 10 
- 	    anchors.centerIn: parent 
- 	    color: 'white' 
-   
- 	    Rectangle { 
- 		width: 50 
- 		height: 30 
- 		radius: 3 
- 		border.color: "#000055" 
- 		border.width: 1 
- 		color: "#5555FF" 
- 		anchors.centerIn: parent 
-   
- 		Text { 
- 		    text: 'OK' 
- 		    anchors.centerIn: parent 
- 		    color: "white" 
- 		} 
- 		MouseArea { 
- 		    anchors.fill: parent 
- 		    onClicked: messagebox.state = 'hidden' 
- 		} 
- 	    } 
-   
- 	} 
- 	states: [ 
- 	    State { 
- 		name: "hidden" 
- 		PropertyChanges { target: messagebox; opacity: 0 } 
- 	    }, 
- 	    State { 
- 		name: "shown" 
- 		PropertyChanges { target: messagebox; opacity: 1 } 
- 	    } 
-   
- 	] 
- 	transitions: [ 
- 	    Transition { 
- 		NumberAnimation { properties: "opacity"; duration: 500 } 
- 	    } 
- 	] 
-     } 
- } 
        import QtQuick 1.0
Rectangle {
    id: rectangle1
    width: 360
    height: 360
    function showBox() {
	messagebox.state = "shown"
    }
    Rectangle {
	// some button
	width: 100
	height: 50
	color: 'red'
	anchors.left: parent.left
	anchors.leftMargin: 5
	anchors.top: parent.top
	anchors.topMargin: 5
	MouseArea {
	    anchors.fill: parent
	    onClicked: showBox()
	}
    }
    Rectangle {
	id: messagebox
	anchors.fill: parent
	color: '#dd000000'
	opacity: 0
	z: 1000
	Rectangle { // box
	    width: 200
	    height: 100
	    radius: 10
	    anchors.centerIn: parent
	    color: 'white'
	    Rectangle {
		width: 50
		height: 30
		radius: 3
		border.color: "#000055"
		border.width: 1
		color: "#5555FF"
		anchors.centerIn: parent
		Text {
		    text: 'OK'
		    anchors.centerIn: parent
		    color: "white"
		}
		MouseArea {
		    anchors.fill: parent
		    onClicked: messagebox.state = 'hidden'
		}
	    }
	}
	states: [
	    State {
		name: "hidden"
		PropertyChanges { target: messagebox; opacity: 0 }
	    },
	    State {
		name: "shown"
		PropertyChanges { target: messagebox; opacity: 1 }
	    }
	]
	transitions: [
	    Transition {
		NumberAnimation { properties: "opacity"; duration: 500 }
	    }
	]
    }
}
To copy to clipboard, switch view to plain text mode 
  
				
			
Bookmarks