Reputation: 22906
import QtQuick 2.8
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4
import QtQuick.Controls 2.1
Window
{
id: head
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Loader
{
id: loader
}
Component
{
id: rect
Window
{
id: ppp
visible: true
width: 164
height: 148
title: qsTr("Hello World")
}
}
Rectangle
{
anchors.fill: parent
color: "blue"
Rectangle
{
id: leftArea
height: 100
width: 100
color: "red"
MouseArea
{
anchors.fill: parent
onClicked:
{
loader.sourceComponent = rect
leftArea.parent = loader
}
}
}
}
When I click on that rectangle, it disapears but it doesn't get shown in the loader's window. Moreover when I maximize the new resultant window the GUI hangs.
Aim is to make the new Loader's window the parent of the rectangle on click.
Upvotes: 0
Views: 45
Reputation: 8277
There's two issues with your code.
parent = loader.item
, not parent = loader
. You don't want the Loader to be your parent, but the item that it has loaded. Loader
{
id: loader
}
Component
{
id: rect
Window
{
id: ppp
visible: true
width: 164
height: 148
title: qsTr("Hello World")
}
}
Rectangle
{
anchors.fill: parent
color: "blue"
Rectangle
{
id: leftArea
height: 100
width: 100
color: "red"
MouseArea
{
anchors.fill: parent
onClicked:
{
loader.sourceComponent = rect
leftArea.parent = loader.item.contentItem
}
}
}
}
Upvotes: 2