Reputation: 137
I have a Rectangle with a MouseArea in ApplicationWindow. By clicking the mousearea, the size of the rectangle should be increased, which works perfectly. But somehow centering the rectangle in the middle of the ApplicationWindow does not work
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
ApplicationWindow {
id: originalWindow
visible: true
width: 1920
height: 1080
title: qsTr("Bookshop Management System")
Rectangle {
id: searchUserButton
x: 450
y: 206
radius: 10
width: 200
height: 200
color: "#ccc8c8"
MouseArea {
anchors.fill: parent
onClicked: {searchUserButton.width = 1100
searchUserButton.height = 600
searchUserButton.anchors.centerIn = originalWindow
rectangle2.visible = false
rectangle3.visible = false
rectangle4.visible = false
rectangle5.visible = false
rectangle6.visible = false
}
}
}
The error code is `Error:
Cannot assign QObject* to QQuickItem*
Upvotes: 1
Views: 1038
Reputation: 326
You already set a width and a height of the searchUserButton, so you only have to correctly set x and y coordinates for this button.
searchUserButton.x = (originalWindow.width - searchUserButton.width) / 2
searchUserButton.y = (originalWindow.height - searchUserButton.height) / 2
Upvotes: 2