Comment créer une nouvelle fenêtre À partir de QML?
y a-t-il un moyen de créer une instance de fenêtre complètement nouvelle, comme une fenêtre enfant de la fenêtre principale QML dans une application QML?
// ChildWindow.qml
Rectangle {
    id: childWindow
    width: 100
    height: 100
    // stuff
}
// main.qml
Rectangle {
    id: window
    width: 1000
    height: 600
    MouseArea {
        anchors.fill: parent
        onClicked: createAWindow(childWindow);
    }
}
je suis en train d'essayer d'éviter d'écrire un Q_OBJECT classe juste pour instanciating la nouvelle fenêtre, dans un nouveau QmlApplicationViewer.
12
                
            
                demandé sur
                opatut
                2011-11-30 18:56:19
            
        2 réponses
il n'y a aucun moyen de créer des fenêtres de haut niveau en utilisant seulement la fonctionnalité QML intégrée.
cependant il y a un projet sur Qt Labs appelé Composants De Bureau, qui contient un composante fenêtre, qui vous permet de créer de nouvelles fenêtres de niveau supérieur.
1
	                    
	                
	                    répondu
	                    sepp2k
	                    2011-11-30 15:18:47
	                
	            Vous pouvez le faire en utilisant Qt.createComponent. Exemple (en utilisant Qt 5.3):
main.qml
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
    id: root
    width: 200; height: 200
    Button {
        anchors.centerIn: parent
        text: qsTr("Click me")
        onClicked: {
            var component = Qt.createComponent("Child.qml")
            var window    = component.createObject(root)
            window.show()
        }
    }
}
Enfant.qml
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
    id: root
    width: 100; height: 100
    Text {
        anchors.centerIn: parent
        text: qsTr("Hello World.")
    }
}
25
	                    
	                
	                    répondu
	                    Kknd
	                    2014-06-25 12:24:34