2017-12-08 1 views
0

home.qml, weather.qml 및 currency.qml과 같은 3 개의 Qml 페이지가 있습니다. home.qml 페이지에서 (올바른 방법으로 생각하면) 3 페이지를로드해야하고 Qml Swipe with Loader를 사용하여 페이지를로드 할 수 있습니다. 1-> 2-> 3 및 3-> 2-> 1과 같은 페이지 사이를 스 와이프해야합니다.메인 페이지에 동적으로 Qml 페이지를로드하고 페이지간에 스 와이프를 만드는 방법은 무엇입니까?

또한 home.qml 페이지가 첫 번째 페이지임을 표시해야합니다. ** doc.qt.io/qt-5/qml-qtquick-controls2-swipeview를 확인합니다. html 링크가 있지만 다른 2 페이지를로드 할 수 없어 슬쩍 할 수 있습니다. 정보를 얻을 수있는 곳에서 Qml 페이지를 메인 페이지로 동적으로로드하고 페이지 사이를 스 와이프 할 수 있습니다.

도움이 필요하십니까?

업데이트 된 작업 코드 : QML 앱 프로젝트의 Qt5.9.2에서 테스트되었습니다.

코드는 간단한 방식으로 표시됩니다. 코드는 다음과 같습니다.

새 VPlay APP를 만듭니다. Main.qml 파일에만있었습니다. 3 페이지 (Page1.qml, Page2.qml 및 Page3.qml)를 추가합니다. Main.qml에서 아래 코드를 추가합니다.

import VPlayApps 1.0 
import QtQuick 2.4 
import QtQuick.Layouts 1.3 
import QtQuick.Controls 2.2 
Page { 
anchors.fill: parent 
// Background 
Rectangle { 
y: 0; width: parent.width; height: parent.height 
gradient: Gradient { 
GradientStop { position: 0.00; color: “#1AD6FD” } 
GradientStop { position: 1.00; color: “#1D62F0” } 
} 
} 
    SwipeView { 
id: view 
currentIndex: 0 
anchors.fill: parent 
anchors.top: parent.top 
        Item{ 
id: firstItem 
Loader { 
// index 0 
id: pageOneLoader 
source: “Page1.qml” 
anchors.fill: parent 
anchors.top: parent.top 
} 
} 

Item{ 
id: secondItem 
Loader { 
// index 1 
id: pageSecondLoader 
source: “Page2.qml” 
anchors.fill: parent 
anchors.top: parent.top 
} 
} 

Item{ 
id: thirdItem 
Loader { 
// index 2 
id: pageThirdLoader 
source: “Page3.qml” 
anchors.fill: parent 
anchors.top: parent.top 
} 
} 
       } 
       PageIndicator { 
id: indicator 
count: view.count 
currentIndex: view.currentIndex 
anchors.bottom: view.bottom 
anchors.horizontalCenter: parent.horizontalCenter 
} 
} 

그리고 각 페이지 (page1, page2 등) 아래 코드를 추가합니다.

// emitting a Signal could be another option 
Component.onDestruction: { 
cleanup() 
} 
+1

시도 코드를 표시하십시오. – derM

+0

@derM 시작하는 법을 모르겠습니다. 모든 예에서는 인라인 페이지 생성과 스 와이프 사용을 보여줍니다. 나는 시작하는 데 도움이 필요하다. – NTMS

+0

왜 '로더'를 사용해야합니까? (이 질문은 당신이나 다른 것을 비판하는 것이 아닙니다. 나는 당신의 유스 케이스를 더 잘 이해해야합니다.) – derM

답변

0

코드는 간단한 방식으로 표시됩니다. 코드는 다음과 같습니다. 새 VPlay APP를 만듭니다. Main.qml 파일에만있었습니다. 3 페이지 (Page1.qml, Page2.qml 및 Page3.qml)를 추가합니다. Main.qml에서 아래 코드를 추가합니다.

import VPlayApps 1.0 
import QtQuick 2.4 
import QtQuick.Layouts 1.3 
import QtQuick.Controls 2.2 
Page { 
anchors.fill: parent 
// Background 
Rectangle { 
y: 0; width: parent.width; height: parent.height 
gradient: Gradient { 
GradientStop { position: 0.00; color: “#1AD6FD” } 
GradientStop { position: 1.00; color: “#1D62F0” } 
} 
} 
    SwipeView { 
id: view 
currentIndex: 0 
anchors.fill: parent 
anchors.top: parent.top 
        Item{ 
id: firstItem 
Loader { 
// index 0 
id: pageOneLoader 
source: “Page1.qml” 
anchors.fill: parent 
anchors.top: parent.top 
} 
} 

Item{ 
id: secondItem 
Loader { 
// index 1 
id: pageSecondLoader 
source: “Page2.qml” 
anchors.fill: parent 
anchors.top: parent.top 
} 
} 

Item{ 
id: thirdItem 
Loader { 
// index 2 
id: pageThirdLoader 
source: “Page3.qml” 
anchors.fill: parent 
anchors.top: parent.top 
} 
} 
       } 
       PageIndicator { 
id: indicator 
count: view.count 
currentIndex: view.currentIndex 
anchors.bottom: view.bottom 
anchors.horizontalCenter: parent.horizontalCenter 
} 
} 

그리고 각 페이지 (PAGE1, 페이지 2 등) 내가 코드를 아래에 추가;

// emitting a Signal could be another option 
Component.onDestruction: { 
cleanup() 
} 
관련 문제