Starting Point of Rectangle in RubberBand implementation
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();
}
Re: Starting Point of Rectangle in RubberBand implementation
Hello,
You can use to have the exact position pointed by the cursor.
Re: Starting Point of Rectangle in RubberBand implementation
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 :)
Re: Starting Point of Rectangle in RubberBand implementation
Thanks for your reply, How can I map event->pos() to the imageLabel ?
Re: Starting Point of Rectangle in RubberBand implementation
QWidget::mapToin your case imageLabel->mapTo..