Results 1 to 6 of 6

Thread: Conditional rubber band selection in QGraphicsView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    29
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question Conditional rubber band selection in QGraphicsView

    I have a QGraphicsView based object in my project, with rubber band selection enabled. In the project, we have several selection modes. In some modes, some types of objects can be selected, and in other modes other types of objects can be selected.
    Anyone have a suggestion as to where I should interfere with the selection of the items, if they are not the type of item that should be selected with the current mode? I've already implemented an event handler that controls mouse press selection, but there don't seem to be events for rubber band selection that I can find.

    Thanks for any suggestions.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Conditional rubber band selection in QGraphicsView

    I think the simplest way to do this would be to set your items 'ItemIsSelectable" flag to QGraphicsItem::ItemIsSelectable when the mode allows the items to be selected, or remove the flag making the item not selectable in modes where items should not be selectable.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2008
    Posts
    29
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: Conditional rubber band selection in QGraphicsView

    That might be simplest in a simple situation, but I have multiple windows, with potentially thousands of items, and the calculation as to whether or not they are selectable is fairly complex. For example, there are several different cursors, and each allows selection of certain types of items, but some of those items are selectable in some windows, and not in others. In the case of a click, I am intercepting the event, as I mentioned above, and that allows me to look at which cursor is selected, which window it's in, and which type of item it is. I don't think that changing the selectable state on the items is practical, unless I can change it in response to the rubber band selection event, which kind of brings me full circle back to my original question. Any other thoughts? (Thanks for the suggestion, by the way.)

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Conditional rubber band selection in QGraphicsView

    I don't quite follow on the problem.
    The fact that you have a complex set of rules to decide which item should be selectable or not, is a code that will have to be written somewhere in your application - there is not way around that.
    Since you want to make the items not/selectable for the rubber band as well, I don't see how you can come around settings the selectable flag on the items, if some items should be selected and others not, under one rubber band.
    The only other way would be to have your select logic run while you drag the rubber band, and deselect them while you do it.
    Not an approach I would recommend, specially as you said you have many items.

    Usually such complex rules to do something, tend to show a not well thought through design.
    So I would suggest as first step to take the time, and optimize the way the selection logic should work.
    And only then go about how to implement it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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, 13:01
  2. How do I clear the rubber band after a selection is done
    By aarelovich in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2010, 13:29
  3. Replies: 2
    Last Post: 17th June 2010, 14:38
  4. How to draw rubber band using XOR
    By lni in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2009, 13:13
  5. Rubber band artifacts?
    By mooreaa in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2008, 19:19

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
  •  
Qt is a trademark of The Qt Company.