情况:
我Dialog
在 QT 有一堂课,我在上面画了一个正方形的栅格。正方形在MySquare
类 ( MySquare: QGraphicsItem
) 中实现。
MySquare 内部有许多函数(mysquare.h protected: )
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
当我单击一个正方形时,它会使用以下函数为我提供正方形的相对坐标。
void MySquare::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
update();
QGraphicsItem::mousePressEvent(event);
qDebug() << "mouse Pressed";
qDebug() << "coordinates:";
qDebug() << "X:"<< x/w << " Y:" << y/h ;
}
其中 x 和 y 是光栅中的 x 和 y 位置,w 和 h 代表宽度和高度
但是我的问题是如何让我的 Dialog 类知道点击了哪个方块?