PDA

View Full Version : RubberBand lines



vandanadk
3rd April 2011, 14:07
hi,

Ive developed a code to upload an image on qlabel.i am able to draw lines on dis image by clicking on 2 points on the image. i need to implement rubberband lines. that is when i click on a point the rubber band line must appear and move along as the mouse moves and should disappear after i click the 2nd point. Ive gone thru QRubberBand documentaion but wasnt sure how to go abt implementing it.Can someone plz help me out ?

thnk u

vandanadk
4th April 2011, 14:56
ok i was able t get the rubberband t work but though ive used QRubberBand::Line i still get a rectangle wen i click and drag. what should i do to get a line??

if (event->type() == QEvent::MouseMove)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (rubber)
rubberBand->setGeometry(QRect(origin,mouseEvent->pos()).normalized());

}

if (event->type() == QEvent::MouseButtonPress)
{
if(c==0)
{
QMouseEvent *mouseEvent1 = static_cast<QMouseEvent*>(event);
if(mouseEvent1->button()==Qt::LeftButton)
{
origin = mouseEvent1->pos();
rubberBand->setGeometry(QRect(origin, QSize()));
rubberBand->show();
rubber = true;

}
}
else
{
c=0;
rubber = false;
rubberBand->hide();
}

aamer4yu
4th April 2011, 19:38
what should i do to get a line??
Draw the line yourself.
From mouse press and mouse move you get the start and end points.
In paintevent draw the line using those points.

vandanadk
5th April 2011, 18:44
ok thank u will do that.