Вы можете перемещать эллипс, используя метод moveCenter
.
void Label::mousePressEvent(QMouseEvent* event){
mousePressed = true;
if( mouse_event->buttons() & Qt::RightButton ){
mCirc.setTopLeft(event->pos());
mCirc.setBottomRight(event->pos());
}
if( mouse_event->buttons() & Qt::LeftButton) {
offset = event->pos();
center = mCirc.center();
}
}
void Label::mouseMoveEvent ( QMouseEvent * mouse_event )
{
...
if(mouse_event->buttons() & Qt::LeftButton) {
QPoint delta = mouse_event->pos() - offset;
mCirc->moveCenter( center + delta);
}
update();
}
Возможно, вы захотите защитить другое действие проверкой правой кнопки.
void Label::mouseMoveEvent ( QMouseEvent * mouse_event )
{
if(mouse_event->type() == QEvent::MouseMove && mousePressed == true){
if(mouse_event->buttons() & Qt::RightButton) {
mCirc.setBottomRight(mouse_event->pos());
}
if(mouse_event->buttons() & Qt::LeftButton) {
QPoint delta = mouse_event->pos() - offset;
mCirc->moveCenter( center + delta);
}
update();
}
}