1

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*
1
  • 1
    try with: searchUserButton.anchors.centerIn = originalWindow.contentItem Commented May 25, 2020 at 14:52

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.