Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

What is the common pattern to implement a selected region dragged by mouse ?

$
0
0
I am quite new on Qt, and I would like to implement a selection made by dragging with the mouse. What is the common pattern/logic to do it ? I have found a clear and nice example which used QRubberBand class that I think will be a good inspiration for what i want to implement: void Widget::mousePressEvent(QMouseEvent *event)  {      origin = event->pos();      if (!rubberBand)          rubberBand = new QRubberBand(QRubberBand::Rectangle, this);      rubberBand->setGeometry(QRect(origin, QSize()));      rubberBand->show();  }    void Widget::mouseMoveEvent(QMouseEvent *event)  {      rubberBand->setGeometry(QRect(origin, event->pos()).normalized());  }    void Widget::mouseReleaseEvent(QMouseEvent *event)  {      rubberBand->hide();      // determine selection, for example using QRect::intersects()      // and QRect::contains().  } But, i think but i’m not sure, that the example is not complete, do we have to add something like paint event or _repaint_for drawing the selection or it is included in the code above….? Also, it will be cool if we can draw from any direction top-left/right corner and bottom-left/right corner, is the example include those things or otherwise what is the “logic” to implement a selection that can start dragging with any direction? Thks in advance for any ideas or enligthenment about those things :)

Viewing all articles
Browse latest Browse all 18427

Trending Articles