Ok, I will bite.
++ QML:
class Dispatcher : public QObject {
Q_OBJECT
public slots:
void click(qreal x, qreal y) {
foreach (QObject * o, objects) {
QMouseEvent * e1 = new QMouseEvent(QEvent::MouseButtonPress, QPointF(x, y), Qt::MouseButton::LeftButton, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier);
QCoreApplication::postEvent(o, e1);
QMouseEvent * e2 = new QMouseEvent(QEvent::MouseButtonRelease, QPointF(x, y), Qt::MouseButton::LeftButton, Qt::MouseButton::LeftButton, Qt::KeyboardModifier::NoModifier);
QCoreApplication::postEvent(o, e2);
}
}
void addTarget(QObject * obj) {
objects.append(obj);
}
private:
QObjectList objects;
};
QML QML, , , .
QML, , , :
MouseArea, . . , , , .
Window {
id: main
visible: true
width: 300
height: 300
x: 100
y: 100
MouseArea {
anchors.fill: parent
onClicked: Dispatcher.click(mouseX, mouseY)
}
Component {
id: comp
Item {
anchors.fill: parent
Text {
id: txt
}
MouseArea {
id: ma
anchors.fill: parent
onClicked: txt.text = "clicked at " + mouseX + ", " + mouseY
}
}
}
Window {
id: w1
visible: true
width: 300
height: 300
x: 420
y: 100
Loader {
anchors.fill: parent
sourceComponent: comp
}
Component.onCompleted: Dispatcher.addTarget(w1)
}
Window {
id: w2
visible: true
width: 300
height: 300
x: 740
y: 100
Loader {
anchors.fill: parent
sourceComponent: comp
}
Component.onCompleted: Dispatcher.addTarget(w2)
}
}
, , , , . . . , ++ .