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. What is the common pattern to implement a selected region dragged by mouse ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 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.
  • G Offline
    G Offline
    Ground
    wrote on last edited by
    #1

    I am quite new on Qt, and I would like to implement a selection made by dragging with the mouse.

    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().
    }@

    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 :)

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      since you use QRect::normalized() it should work as expected.

      But why don't you just try it yourself within 2 mins?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Ground
        wrote on last edited by
        #3

        Ok, thanks, i just wanted to know if at looking at the code, it is possible to see where "the any direction thing" is implemented as i am trying to understand the structure of this kind of code(mouse event...)
        Sorry, the compilation is very long on my computer(don't know if it is because of my computer or the program..), but i will try when i will have long free time :)

        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