@Bidski
Hi
Not in Qt. ( maybe if old)
I would guess from the attempt to snap the
coordinates but cant say for sure.
However, please see this sample
https://www.dropbox.com/s/gp9rvylkb18xnl3/myrubberband.zip?dl=0
[image: Cqi71U.png]
Drag the rubberband and release
It cuts what is expected and show in label
So all seems to be fine :)
#include <QMouseEvent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
move_rubberband = false;
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
rubberBand->setGeometry(0,0,50,50);
rubberBand->show();
}
void MainWindow::mousePressEvent(QMouseEvent *e)
{
if(rubberBand->geometry().contains(e->pos()))
{
rubberband_offset = e->pos() - rubberBand->pos();
move_rubberband = true;
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
if(move_rubberband)
{
rubberBand->move(e->pos() - rubberband_offset);
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent *e)
{
move_rubberband = false;
QRect r=rubberBand->geometry();
rubberBand->hide();
QPixmap p=grab(r); // no need for mapTo here.
ui->label->setPixmap(p);
rubberBand->show();
rubberBand->raise();
}