I have an object inherited from qquickwindow
with an overridden mousePressEvent
method.
.h
class FWindow : public QQuickWindow
{
Q_OBJECT
public:
FWindow(QQuickWindow* parent = Q_NULLPTR);
protected:
virtual void mousePressEvent(QMouseEvent* event) override;
};
.cpp
void FWindow::mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
{
...
}
QQuickWindow::mousePressEvent(event);
}
The problem is that when I add a Rectangle
with MouseArea
to a qml file, it does not react in any way. The signal goes to FWindow
, not MouseArea
. How to fix it?
.qml
FWindow
{
visible: true;
Rectangle
{
width: 50;
height: 50;
color: "green";
anchors.verticalCenter: parent.verticalCenter;
anchors.horizontalCenter: parent.horizontalCenter;
MouseArea
{
anchors.fill: parent;
onClicked:
{
console.log("clicked");
}
}
}
}
该文档说默认情况下接受QQuickItem::mousePressEvent
收到的QMouseEvent* event
,如果您不想接受它,则必须调用event->ignore()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.