Discussion:
[Interest] [QML] How to create a sub Window for Window {...}
Yuchen Deng
11 years ago
Permalink
hi, list! I have to ask for help because I can't create an sub window on
Window {...}.
I've tried some days, after Google still can't solved my problem.

main.qml
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
id: mainWindow
visible: true
width: 760; height: 520
color: "red"
property variant win; // you can hold this as a reference..
Text {
text: "Click here to open sub window 2!"
anchors.centerIn: parent
}
Window {
id: subWindow_1
width: 555
height: 333
visible: true
flags: Qt.SubWindow
}
MouseArea {
anchors.fill: parent
onClicked: {
var component = Qt.createComponent("subwindow2.qml");
win = component.createObject(mainWindow);
win.show();
}
}
}
subwindow2.qml
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
id: subWindow_2
visible: true
width: 500; height: 300
color: "blue"
flags: Qt.SubWindow
Rectangle {
anchors.fill: parent
color: "lightGrey"
Text {
anchors.centerIn: parent
text: "Sub Window 2"
}
}
}
See the code, it's can open two window, But can't open as sub window in
parent.
Any help / tips are very welcome!
Thanks you!
--
Best Regards
Yuchen
Rutledge Shawn
11 years ago
Permalink
What do you mean by sub window? If you mean you are trying to create an MDI interface, with a window acting as a desktop and having more windows inside, that's not supported in Qt Quick and is unlikely at this point, since the widgets implementation turned out to be quite bug-prone, and MDI has anyway mostly fallen out of fashion. When you declare a Window inside a Window, it becomes "transient for" the outer window: a hint is given to the window manager that they are related to each other, so usually it will be shown centered over its transient parent.
...
Yuchen Deng
11 years ago
Permalink
Actually, I don't really want an MDI interface. I just want load or open
another qml as child Window show inside the parent.
like this (using QML's Rectangle):
Failed to load image: http://picpaste.com/sub-window-y43R1Kuf.png
not like this (using QML's Window):
Failed to load image: http://picpaste.com/no-sub-window-Jq7qeOu5.png
...
--
Best Regards
Yuchen
Filip Piechocki
11 years ago
Permalink
So just use Rectangle :) or Item if you just want an empty item, or
Component to load some QML from file.

BR,
Filip Piechocki
...
BOUCARD Olivier
11 years ago
Permalink
The best way is to use a Loader item.

Olivier



Le Lundi 2 juin 2014 10h58, Filip Piechocki <***@gmail.com> a écrit :



So just use Rectangle :) or Item if you just want an empty item, or Component to load some QML from file.

BR,
Filip Piechocki



On Mon, Jun 2, 2014 at 9:51 AM, Yuchen Deng <***@gmail.com> wrote:

Actually, I don't really want an MDI interface. I just want load or open another qml as child Window show inside the parent.
...
Yuchen Deng
11 years ago
Permalink
Post by BOUCARD Olivier
The best way is to use a Loader item.
thx. like this?
Post by BOUCARD Olivier
import QtQuick 2.2
Rectangle {
id: root
visible: true
width: 760; height: 520
color: "red"
Loader { id: pageLoader }
MouseArea {
anchors.fill: parent
onClicked: pageLoader.source = "subwindow2.qml"
}
}
--
Best Regards
Yuchen
BOUCARD Olivier
11 years ago
Permalink
Yes Yuchen. But you should anchor the Loader like any other item.



Le Lundi 2 juin 2014 12h23, Yuchen Deng <***@gmail.com> a écrit :



2014-06-02 16:59 GMT+08:00 BOUCARD Olivier <***@yahoo.fr>:

The best way is to use a Loader item.
thx. like this?
import QtQuick 2.2
Rectangle {
    id: root
    visible: true
    width: 760; height: 520
    color: "red"
    Loader { id: pageLoader }
    MouseArea {
        anchors.fill: parent
        onClicked: pageLoader.source = "subwindow2.qml"
    }    
}
--
Best Regards
Yuchen
Yuchen Deng
11 years ago
Permalink
Got it, thanks!
Post by BOUCARD Olivier
But you should anchor the Loader like any other item.
--
Best Regards
Yuchen
Continue reading on narkive:
Loading...