Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get a Rubberband Line
Forum Updated to NodeBB v4.3 + New Features

How to get a Rubberband Line

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #1

    I can get the rubberband rectangle to work, but not the rubberband line. Has anyone made the QRubberBand to work providing just a line and not a rectangle?
    In the past I have used an off screen buffer to draw into and bitblit it to the visible screen (window) and then draw the rubberband line on the screen. It worked and was fast--on both OS/2 and Windows NT. Another possibility is to place another widget with a transparent background over the widget in which I am doing my actual drawing and use it to show the rubberband line. Or, if the number of items to be drawn and the GPU strong enough, then I could draw on the widget and then draw the rubberband line and redraw all when the mouse moves. Anybody tried any of the above?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show the code you are using for the rubber band line ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • O Offline
        O Offline
        ofmrew
        wrote on last edited by
        #3

        The code is nearly the same as the Qt documentation, but with Line specified.

        void MyCanvas::mousePressEvent(QMouseEvent *e)
        {
        origin = e->pos();
        rubberRect = new QRubberBand(QRubberBand::Line, this);
        rubberRect->setGeometry(QRect(origin, QSize()));
        //rubberRect->move();
        rubberRect->show();
        qDebug() << origin;
        }

        void MyCanvas::mouseMoveEvent(QMouseEvent *e)
        {
        qDebug() << e->pos();
        rubberRect->setGeometry(QRect(origin, e->pos()).normalized());
        //rubberRect->move(e->pos());
        }

        void MyCanvas::mouseReleaseEvent(QMouseEvent *e)
        {
        corner = e->pos();
        rubberRect->hide();
        }
        This code produces the same results as using Rectangle.

        I must point out the this will only solve part of my problem. What I also want to do, and have done in the past, is to move a sprite on the hidden mouse pointer. When the sprite nears a rectilinear object it will orientate itself perpendicular to the object and a dot will appear on the line representing the correlation point.

        I

        1 Reply Last reply
        0
        • O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          I resolved this problem by using a Pixmap to double-buffer. Then I can draw a rubber line or rectangle or move a sprite using the Pixmap to restore the original image after each move, thus no need to try to use QRubberband and I am not limited, but it is a little more programming.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved