Get the current page of stackView?
-
Hello, I switch the content in the stackview through the button event, so I define two components and use id as the unique identifier.
But I want to get whether the current page is a certain page when the button is clicked, and if it is, I won’t switch it. So is the current page content obtained through view or currentItem? When obtaining future content and comparing components, should it be compared with the component id or with what to determine whether it is a certain component? (Actually, where does the following if statement compare with the current content of the stackview and the component? ID?)
code show as below:Button { id: closeBtn x: 400 y: 0 width: 25 height: 25 text: qsTr("close") onClicked: { if(pages.currentItem == license) { return }else { pages.push(license) } } } StackView { id: pages x: 0 y: 25 width: 500 height: 316 anchors.fill: parent initialItem: welcome replaceEnter: Transition { PropertyAnimation { target: stackView property: "opacity" from: 0 to: 1 duration:700 easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 1.5 } } replaceExit: Transition { PropertyAnimation { target: stackView property: "opacity" from: 1 to: 0 duration:500 easing.type: Easing.InOutElastic; easing.amplitude: 2.0; easing.period: 1.5 } } Component { id: welcome Rectangle { width: 200 height: 200 x: 20 y: 50 color: "#00c20c" } } Component { id: license Rectangle { width: 200 height: 200 x: 200 y: 50 color: "#FFC0CB" } }
-
@Nan-Feng said in Get the current page of stackView?:
Hello, I switch the content in the stackview through the button event, so I define two components and use id as the unique identifier.
But I want to get whether the current page is a certain page when the button is clicked, and if it is, I won’t switch it. So is the current page content obtained through view or currentItem? When obtaining future content and comparing components, should it be compared with the component id or with what to determine whether it is a certain component? (Actually, where does the following if statement compare with the current content of the stackview and the component? ID?)I think you are mixing up something.
WithComponent
, you are creating a new component type inside the current QML file. Like you would do it with an external QML file.
ButStackView.currentItem
is an instance of a component.=> You are trying to compare potatoes and oranges ;)
You can do it by creating an instance of component
license
or by comparing component type.