[英]how to add qml file in swipeview
I was trying to use swipe view In swipe view i need to add qml file into it so every swipe i need to get one qml file to show i need to get 7 qml file in 7 swipe and i need add global property in every swipe view我试图使用滑动视图 在滑动视图中我需要向其中添加 qml 文件所以每次滑动我都需要获取一个 qml 文件来显示我需要在 7 次滑动中获取 7 qml 文件并且我需要在每次滑动视图中添加全局属性
I try to loader to get qml file but i am not able to add global property Because the qml file are already used in another swipe view i need to use global property and change the value我尝试加载程序以获取 qml 文件,但我无法添加全局属性因为 qml 文件已在另一个滑动视图中使用,我需要使用全局属性并更改值
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Page
{
id:mfcscreens
Rectangle{
height:wavescreen.height
width: wavescreen.width
SwipeView{
id:swipeview
anchors.fill:parent
currentIndex: 0
spacing: 4
Item {
id:page1
Loader{
id:mainwavescreen
source: "MfcWavefoam.qml"
}
}
Item {
id:page2
Loader{
id:leads12
source: "Leads12.qml"
Item{
property int speed: 5;
property int gain: 10;
property int xValue: 976
property int degreeValue: 143
}
}
}
Item {
id:page3
Loader{
id:leads3of1
source: "Leads3of1.qml"
}
}
Item {
id:page4
Loader{
id:leads3of2
source: "Leads3of2.qml"
}
}
Item {
id:page5
Loader{
id:leads3of3
source: "Leads3of3.qml"
}
}
Item {
id:page6
Loader{
id:leads3of4
source: "Leads3of4.qml"
}
}
Item {
id:page7
Loader{
id:leads6of1
source: "Leads6of1.qml"
}
}
Item {
id:page8
Loader{
id:leads6of2
source: "Leads6of2.qml"
}
}
}
}
}
I think, you have several problems.我想,你有几个问题。 So start with the first one.所以从第一个开始。 For your SwipeView to work you should provide a PageIndicator.为了使 SwipeView 正常工作,您应该提供一个 PageIndicator。 So add something like that below our view:所以在我们的视图下面添加类似的东西:
PageIndicator {
id: indicator
count: swipeView.count
currentIndex: swipeView.currentIndex
anchors.bottom: swipeView.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
You don't need to use loaders for your pages.您不需要为您的页面使用加载程序。 You could just add the components directly to your items:您可以直接将组件添加到您的项目中:
Item {
id:page8
// if your file name is called Leads6of2.qml and is part of your project
Leads6of2 {}
}
The part with the global property is unclear to me.我不清楚具有全局属性的部分。 Please rephrase this problem!请重新表述这个问题!
At this stage, from what you convey in your use case, Loader
isn't required.在此阶段,根据您在用例中传达的信息,不需要Loader
。 Particularly if the number of Pages in your SwipeView
is static. Then, you definitely do not need to use Loader
.特别是如果你的SwipeView
中的 Pages 数量是 static。那么,你肯定不需要使用Loader
。
The following demonstrates:下面演示:
SwipeView
with 3 pages一个包含 3 个页面的SwipeView
speed
, gain
, xValue
and degreeValue
property defined which all the children Pages
can view and modify父页面定义了全局speed
、 gain
、 xValue
和degreeValue
属性,所有子Pages
都可以查看和修改这些属性import QtQuick
import QtQuick.Controls
Page {
property int speed: 5
property int gain: 10
property int xValue: 976
property int degreeValue: 143
SwipeView {
anchors.fill: parent
MfcWaveform { }
Leads12 { }
Leads3of1 { }
}
}
// MfcWaveform.qml
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Page {
ColumnLayout {
anchors.centerIn: parent
Text {
text: qsTr("MfcWaveform")
}
Button {
text: qsTr("Speed: %1").arg(speed)
onClicked: speed = speed + 1
}
Button {
text: qsTr("Gain: %1").arg(gain)
onClicked: gain = gain + 1
}
Button {
text: qsTr("xValue: %1").arg(xValue)
onClicked: xValue = xValue + 1
}
Button {
text: qsTr("degreeValue: %1").arg(degreeValue)
onClicked: degreeValue = degreeValue + 1
}
}
}
// Leads12.qml
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Page {
ColumnLayout {
anchors.centerIn: parent
Text {
text: qsTr("Leads12")
}
Button {
text: qsTr("Speed: %1").arg(speed)
onClicked: speed = speed + 1
}
Button {
text: qsTr("Gain: %1").arg(gain)
onClicked: gain = gain + 1
}
Button {
text: qsTr("xValue: %1").arg(xValue)
onClicked: xValue = xValue + 1
}
Button {
text: qsTr("degreeValue: %1").arg(degreeValue)
onClicked: degreeValue = degreeValue + 1
}
}
}
// Leads3of1.qml
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Page {
ColumnLayout {
anchors.centerIn: parent
Text {
text: qsTr("Leads3of1")
}
Button {
text: qsTr("Speed: %1").arg(speed)
onClicked: speed = speed + 1
}
Button {
text: qsTr("Gain: %1").arg(gain)
onClicked: gain = gain + 1
}
Button {
text: qsTr("xValue: %1").arg(xValue)
onClicked: xValue = xValue + 1
}
Button {
text: qsTr("degreeValue: %1").arg(degreeValue)
onClicked: degreeValue = degreeValue + 1
}
}
}
You can Try it Online!您可以在线试用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.