Results 1 to 8 of 8

Thread: Drawing a selection rectangle

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: Drawing a selection rectangle

    I have this in my inherited GraphicsScene:
    Qt Code:
    1. void MyGraphicsScene::mousePressEvent ( QGraphicsSceneMouseEvent * event )
    2. {
    3. event->ignore();
    4.  
    5. // Reset selectionArea
    6. setSelectionArea(QPainterPath());
    7.  
    8. // Always remember to call parents mousePressEvent
    9. QGraphicsScene::mousePressEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. void MyGraphicsScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
    2. {
    3. event->ignore();
    4.  
    5. bool ctrl = (event->modifiers() == Qt::ControlModifier);
    6.  
    7. QPainterPath tmpPath = selectionArea();
    8. if(tmpPath.isEmpty())
    9. {
    10. // if ctrl pressed, then toggle selection
    11. emit select(event->scenePos(), ctrl);
    12. }
    13. else
    14. {
    15. // if ctrl pressed, then add selection
    16. emit select(tmpPath, ctrl);
    17. }
    18.  
    19. // Always remember to call parents mousePressEvent
    20. QGraphicsScene::mouseReleaseEvent(event);
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 
    I just inherited QGraphicsScene locally just to re-implement these two functions. This is the complete code I use in these two functions. You may not need all, but what I do, is to emit the signal with the path (selection rectangle) and if the user has pressed ctrl (adding elements)

    Hope this helps and I didn't misunderstand your question.

  2. #2
    Join Date
    Mar 2006
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: Drawing a selection rectangle

    Quote Originally Posted by zarkzervo View Post
    Hope this helps and I didn't misunderstand your question.
    You didn't but since I do not use QGraphicsScene...

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. How to remove the dotted rectangle of selection
    By jiveaxe in forum Qt Programming
    Replies: 5
    Last Post: 18th April 2010, 22:00
  3. QTableView, no selection rectangle
    By alisami in forum Qt Programming
    Replies: 13
    Last Post: 25th December 2008, 19:50
  4. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  5. How to paint a selection rectangle on a pixmap?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 8th January 2006, 19:52

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.