gpt4 book ai didi

c++ - QML 动画结束后调用 C++ 函数

转载 作者:行者123 更新时间:2023-11-30 01:42:18 30 4
gpt4 key购买 nike

我需要在 SwipeView 动画结束后从 UI 调用带有参数的 C++ 类方法。

主要.ui

ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")

SwipeView {
id: swipeView
anchors.fill: parent

Page1 {
id: page1
}

Page2{
id: page2
}
}

XOR {
id: xor
onXorEnded: {
//swipeView.setCurrentIndex(0)
}
onQChanged: {
page2.bar.value = xor.getq()
}
}

Page1Form.ui.qml

Page1Form {



kpButton.onClicked: {
kpDialog.visible = true
}

xorButton.onClicked: {
swipeView.setCurrentIndex(1)
xor.crypt(file_path.text, key_path.text, out_path.text)
}

fpButton.onClicked:{
fpDialog.visible = true
}


FileDialog {
id: fpDialog
onAccepted: {
file_path.text = fpDialog.fileUrl
}
}

FileDialog {
id: kpDialog
onAccepted: {
key_path.text = kpDialog.fileUrl
}
}
}

似乎在 xorButton.onClicked 中 xoring 在滑动 View 动画结束之前开始。现在如何运作:Imgur

最佳答案

作为解决方法,您可以将您的操作绑定(bind)到索引更改:

xorButton.onClicked: {
swipeView.setCurrentIndex(1)
}


SwipeView {
id: swipeView
onCurrentItemChanged: {
if(currentIndex == 1)
xor.crypt(file_path.text, key_path.text, out_path.text)
}
}

但无论如何,它不会在动画结束时触发。

作为另一种解决方法,您可以使用 StackView。它有更多的属性来控制动画。此控件的另一个优点是用户无法在您不期望的时候滑动它。在您的情况下,用户只需轻扫即可。还有一个优点是页面在您不需要时不会占用内存。

import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 2.0


Window {
visible: true
width: 800
height: 800
StackView {
id: view
anchors.fill: parent
initialItem: page1
onBusyChanged: {
if(!busy && currentItem.objectName == "page2")
currentItem.run();
}
}
Component {
id: page1
Rectangle {
color: "green"
objectName: "page1"
Button {
anchors.centerIn: parent
text: "swipe me"
onClicked:
view.push(page2)
}
}
}

Component {
id: page2
Rectangle {
color: "yellow"
objectName: "page2"
function run() { sign.visible = true; }

Rectangle {
id: sign
anchors.centerIn: parent
width: 100
height: 100
radius: 50
color: "red"
visible: false
}
}
}

}

关于c++ - QML 动画结束后调用 C++ 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39794160/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com