Hi how to use QRubberBand class to draw a line. According to docs, we can either draw a rectangle or a line. I'm able to draw a rectangle but not a line. Here is the sample code I have tried
Myline
::Myline( QWidget *parent, Qt
::WFlags flags
) RBand = 0;
}
first_pt = event->pos();
last_pt = event->pos();
if (!RBand)
RBand
->setGeometry
(QRect(first_pt, last_pt
));
RBand->show();
}
last_pt = event->pos();
RBand
->setGeometry
(QRect(first_pt, last_pt
));
}
last_pt = event->pos();
RBand->hide();
}
Myline::Myline( QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags){
RBand = 0;
}
void Myline::mousePressEvent(QMouseEvent *event){
first_pt = event->pos();
last_pt = event->pos();
if (!RBand)
RBand = new QRubberBand(QRubberBand::Line, this);
RBand->setGeometry(QRect(first_pt, last_pt));
RBand->show();
}
void Myline::mouseMoveEvent(QMouseEvent *event) {
last_pt = event->pos();
RBand->setGeometry(QRect(first_pt, last_pt));
}
void Myline::mouseReleaseEvent(QMouseEvent *event) {
last_pt = event->pos();
RBand->hide();
}
To copy to clipboard, switch view to plain text mode
Thanks
Bookmarks