[solved] How to get the center coordinate of moving circle by mouse?
-
Hi...
Recently I make a circle using QGraphicsEllipsItem, and it movable by mouse click and drag. The problem is: I cannot detect the center of this circle. I want to detect every coordinate when user move the mouse but it always shows the center of my scene. Very appreciate if there is some help and suggestion. Thank you...
@
void HandleItem::paint( QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
paint->setPen( m_color );
paint->setBrush( m_color );QRectF rect = boundingRect();
QVector<QPointF> points;
QRect frame;
switch( m_role )
{
case CenterHandle:
paint->drawEllipse( rect );
frame = paint->window();
qDebug() << "coordinate center ellips(x,y) : " << frame.center().x()<<" , "
<< frame.center().y();
break;case RightHandle:
.....
}
}
@ -
Get it from boundingRect() - after all those are the coordinates you are using to draw the ellipse.
-
I try to get it from boundingRect(), when the item was moved it still detect the same coordinate, but now it always display the coordinate of the item center. How to detect the new center coordinate after it was moved? I appreciate if there is other suggestion, the boundingRect() code:
@
QRectF HandleItem::boundingRect() const
{
QPointF point = m_item->boundingRect().center();switch( m_role )
{
case CenterHandle:
qDebug() << "coordinate of the center (x,y) : " << m_item-> boundingRect().center().x() <<" , " << m_item-> boundingRect().center().y();
return QRectF( point-QPointF(15, 15), QSize( 30, 30 ) );case RightHandle:
...
}return QRectF();
}
@ -
is sceneBoundingRect() what you are looking for?