Results 1 to 4 of 4

Thread: RubberBand lines

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default RubberBand lines

    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

  2. #2
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: RubberBand lines

    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();
    }

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RubberBand lines

    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.

  4. #4
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: RubberBand lines

    ok thank u will do that.

Similar Threads

  1. How to keep rubberband on the QwtPlot?
    By xujiqiang0927 in forum Qwt
    Replies: 2
    Last Post: 3rd June 2010, 02:46
  2. rubberband selection
    By franco.amato in forum Qt Programming
    Replies: 0
    Last Post: 22nd March 2010, 18:55
  3. Drawing a Rubberband
    By daviddoria in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 14:32
  4. QGV: ItemIgnoresTransformations and RubberBand
    By Vladimir in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2007, 14:38
  5. Rubberband zoom
    By sreedhar in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2006, 11:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.