2017-12-08 13 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

なぜあなたは 'Loader'を使う必要がありますか? (この質問は、あなたや他の人を批判することではありません。私はあなたのユースケースをより良く理解する必要があります) – 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 
} 
} 

各ページ(ページ1、PAGE2など)。

// emitting a Signal could be another option 
Component.onDestruction: { 
cleanup() 
} 
関連する問題