Qml Error: Cannot assign QObject* to QQuickItem
Qml Error: Cannot assign QObject* to QQuickItem
我在 ApplicationWindow 中有一个带有 MouseArea 的矩形。通过单击鼠标区域,矩形的大小应该会增加,效果很好。但是以某种方式将矩形居中在 ApplicationWindow 的中间不起作用
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
}
}
}
错误代码是`错误:
Cannot assign QObject* to QQuickItem*
您已经设置了 searchUserButton 的宽度和高度,因此您只需正确设置该按钮的 x 和 y 坐标。
searchUserButton.x = (originalWindow.width - searchUserButton.width) / 2
searchUserButton.y = (originalWindow.height - searchUserButton.height) / 2
我在 ApplicationWindow 中有一个带有 MouseArea 的矩形。通过单击鼠标区域,矩形的大小应该会增加,效果很好。但是以某种方式将矩形居中在 ApplicationWindow 的中间不起作用
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
}
}
}
错误代码是`错误:
Cannot assign QObject* to QQuickItem*
您已经设置了 searchUserButton 的宽度和高度,因此您只需正确设置该按钮的 x 和 y 坐标。
searchUserButton.x = (originalWindow.width - searchUserButton.width) / 2
searchUserButton.y = (originalWindow.height - searchUserButton.height) / 2