Results 1 to 3 of 3

Thread: Something like a line rubber band but that can be diagonal?

  1. #1
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Something like a line rubber band but that can be diagonal?

    Hello,
    I want to do a graphic program with the possibility of drawing a straight line segment by clicking on a point that represents the start, dragging the mouse and releasing it at the other end. Then a line is drawn. So far , I can program this, but to make it super user friendly I would like the look and feel to be like stretching a rubber band, in other words there should be a
    line from the cursor to the start point that is continuously redrawn as the mouse is moved, and that involves erasing the old
    line. All of this needs to be done without flicker. Any suggestions?
    It seems that QrubberBand can draw lines, but they have to be horizontal or vertical.

    Oh, I am aware that there is a graphics scene demo that provides something like this, but I have been avoiding graphics scenes so far because I am worried that the background scene which has thousands of static objects (it's a map of a town with thousands of buildings) might overload the graphics scene. Is my fear justified?

    Thankyou
    Henri
    Last edited by feraudyh; 16th June 2010 at 21:11.

  2. #2
    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: Something like a line rubber band but that can be diagonal?

    You can keep a track of current mouse move position in a member variable.
    On mouse click set drawLine = true.

    Then in paintEvent,
    Qt Code:
    1. if(drawLine)
    2. {
    3. // draw line from mousePressPoint to current mouse move point...
    4. }
    To copy to clipboard, switch view to plain text mode 
    That should work..

  3. #3
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Something like a line rubber band but that can be diagonal?

    Thanykou for the suggestion which I have successfully implemented.
    I'd just like to add two remarks:
    Since my appllication allows for zooming and moving I have to take the viewport into account by converting mouse coordinates (event->pos()) to real world coordinates which I pass on to the line drawing function.
    In the method MouseMoveEvent the update of the coordinates corresponding to the mouse position needs to be followied by an update() or else the Painter event is is not launched.
    Despite this I see no flicker related to redrawing the map beneath, and this comes as a surprise.Maybe it's because it's so damn fast.

Similar Threads

  1. How can I implement rubber-band with graphics view items?
    By FinderCheng in forum Qt Programming
    Replies: 6
    Last Post: 14th February 2013, 12:01
  2. QRubberband- Mouse clicked on Rubber band area
    By bismitapadhy in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2010, 08:10
  3. How to draw rubber band using XOR
    By lni in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2009, 12:13
  4. Rubber band artifacts?
    By mooreaa in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2008, 18:19
  5. QHeaderView -- diagonal headers?
    By vycke in forum Qt Programming
    Replies: 7
    Last Post: 28th April 2008, 23:54

Tags for this Thread

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.