PDA

View Full Version : Starting Point of Rectangle in RubberBand implementation



cdemirkir
10th July 2007, 08:23
Hello everyone
I've tested the following RubberBand code for an image viewer. But RubberBand rectangle starts at a point a little below the mouse cursor icon instead of at the tip point mouse cursor icon. What can be the reason for this and How can I fix this situation ?

Sincerely
Cem

void ImageMarker::mousePressEvent(QMouseEvent *event)
{
origin = event->pos();

if (!rubberBand)
{
rubberBand = new QRubberBand(QRubberBand::Rectangle, imageLabel);
}

rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
}

void ImageMarker::mouseMoveEvent(QMouseEvent *event)
{
rubberBand->setGeometry(QRect(origin, event->pos()));
}

void ImageMarker::mouseReleaseEvent(QMouseEvent *event)
{
rubberBand->hide();
}

guilugi
10th July 2007, 08:26
Hello,

You can use
QCursor::pos() to have the exact position pointed by the cursor.

Gopala Krishna
10th July 2007, 14:34
You are passing imageLabel as parent of rubberband instead of this(ImageMarker) and hence the coordinates differ. Try setting this as rubberBand's parent.
Another way is to map event->pos() to the imageLabel if you want rubberBand's parent to be imageLabel.

Please wrap the code you post with code tags :)

cdemirkir
10th July 2007, 14:54
Thanks for your reply, How can I map event->pos() to the imageLabel ?

Gopala Krishna
10th July 2007, 15:05
QWidget::mapTo
in your case imageLabel->mapTo..