Как мне создать кнопку, которая перемещает значение y формы на 10 при каждом нажатии кнопки? Это то, что я имею до сих пор, но это только увеличивает значение y один раз. У меня есть файл QML, файл cpp, и файл .pro, код для всех трех вещей приведен ниже.
Файл Main.cpp:
#include <QGuiApplication>
#include <QQuickView>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQuickView view;
view.setSource(QUrl("qrc:/qml/MyRectangle/MyRectangle.qml"));
if (!view.errors().isEmpty())
return -1;
view.show();
app.exec();
}
Файл MyRectangle.qml:
// This is the shape I want to move up the y axis
Rectangle {
id: rectangle333
x: 461
y: 187
width: 731
height: 1
color:"#ef5350"
z: 2
}
// This is the "button" I want the user to press, that would trigger the movement.
Rectangle {
id: myRect
width: 18
height: 18
color: "transparent"
x: 232
y: 250
z:132
MouseArea {
id: mouseArea5
anchors.fill: parent
onClicked: myRect.state == 'clicked' ? myRect.state = "" :
myRect.state = 'clicked';
}
states: [
State {
name: "clicked"
// Rectangle333 is the id of the shape that I want to move up the y axis.
PropertyChanges { target: rectangle333; y:1}
}
]
}