当前位置: 代码迷 >> QT开发 >> qml如何实现多个页面的切换
  详细解决方案

qml如何实现多个页面的切换

热度:520   发布时间:2016-04-25 02:56:48.0
qml怎么实现多个页面的切换
在qml中,怎么实现在主窗体main.qml点击按钮后切换到另一个.qml页面
------解决思路----------------------
查看StackView
------解决思路----------------------
今天又看到两种切换方式,你可以参考一下

Item {    
    width: 200; height: 200       
    Loader { id: pageLoader }      
    MouseArea {         anchors.fill: parent         onClicked: pageLoader.source = "Page1.qml"    } 
    } 


另外一个方法是用createComponent
 Item {     
    id: container     
    width: 300; height: 300       
    function loadButton() {        
        var component = Qt.createComponent("Button.qml");         
        if (component.status == Component.Ready) {            
           var button = component.createObject(container);             
           button.color = "red";         
         }     
     }       
    Component.onCompleted: loadButton()
 } 

------解决思路----------------------
3楼StackView是正解
  相关解决方案