Results 1 to 6 of 6

Thread: Rubberband Item Selection

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Rubberband Item Selection

    Hi all,

    I implemented my own rubberband to perform zooming. I'm done with all zooming stuff but selecting. I wrote the following code to do selection;

    Qt Code:
    1. void Scene::performRubberbandSelection(QRectF* pRect)
    2. {
    3. QList<QGraphicsItem*> itemList = items(*pRect, Qt::IntersectsItemShape);
    4.  
    5. if(itemList.size() == 0)
    6. return;
    7.  
    8. for( int i=0; i<itemList.size();i++)
    9. {
    10. if(itemList.at(i)->type() == 7)
    11. {
    12. continue;
    13. }
    14. else
    15. cout<<itemList.at(i)<<endl;//to test
    16.  
    17.  
    18. itemList.at(i)->setSelected(true);
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    but the problem is in items(...) method. it returns only one root item but not the others in the rubberband rectangle. What could go wrong here?

    Thanks in advance

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rubberband Item Selection

    Maybe a problem conversion coordinates, or offset.

    Is pRect expressed in scene coordinates?

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Rubberband Item Selection

    Hımm, you are right. it seems rectangle points defined it's local coordinate system. how could I fix this?

    But let me remind you, itemlist is the problematic. I mean there is a problem before finding the intersections.
    Last edited by zgulser; 22nd October 2009 at 12:06.

  4. #4
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rubberband Item Selection

    The use of QGraphicsScene::items requires that the rect passed in argument is in scene coordinate.

    So, check where your rect is computed,
    then use QGraphicsView::mapToScene to convert from mouse position to scene position or QGraphicsItem::mapRectToScene from local coordinates to scene coordinates.

  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Rubberband Item Selection

    Hi,

    I check the coordinates of the rectangle and I found it's top left point is (0,0). In order to get rid of this local coordinates, I used mapToScene() but it still returns (0,0). But what I don't understand is how the view map the QRectF's points which are not belong to the scene.
    Last edited by zgulser; 23rd October 2009 at 08:20.

  6. #6
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rubberband Item Selection

    Your Scene:erformRubberbandSelection seems right.

    I think the problem resides in the way you are computing the rect before passing it to the method.

    So, to sum up :

    * if you are getting cursor position from QMouseEvent in a mouse event of the view use QGraphicsView::mapToScene. This will convert pixel coordinates of the viewport into scene coordinates (it is a widget)
    * if you are computing the rect from an item (why not?) from a QGraphicsSceneMouseEvent in an item mouse event, use QGraphicsItem::MapToSceneto convert from local coordinate to scene coordinates.


    In the case you dont get rid of this, just post the code of the method involved in the computation of your rubberband from the mouse events to the your performRubberbandSelection()

Similar Threads

  1. [SOLVED] QTreeView drawing selection with icons
    By Timewarp in forum Qt Programming
    Replies: 7
    Last Post: 7th February 2013, 07:52
  2. Replies: 1
    Last Post: 18th November 2009, 23:21
  3. QLineEdit persistent selection
    By elmo in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2009, 13:15
  4. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 19:54
  5. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31

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.