Results 1 to 8 of 8

Thread: QGraphicsItem with QSizeGrip

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem with QSizeGrip

    Now, for MySizeGripQGraphicsItem, how can I detect dragging a portion of QGraphicsItem namely the corners via mouseEvent's?
    You will just have to test if the user drags those corners. To see this is easy, because you know the position of your MySizeGripQGraphicsItem ( the resize handles are at the corners of the item ).
    Then you can translate QMouseEvent:os() (from mouseMoveEvent ) to parent ( graphics scene ) coordinates and resize the items.

    To know in mouseMoveEvent exactly what corner is dragged, you could use a convenience enum, like:

    Qt Code:
    1. typedef enum EResizeHandle
    2. {
    3. eNone,
    4. eHandleTopLeft,
    5. eHandleTop,
    6. eHandleTopRight,
    7. eHandleRight,
    8. eHandleBottomRight,
    9. ...
    10. } EResizeHandle;
    To copy to clipboard, switch view to plain text mode 
    Assuming you have a member of type EResizeHandle:
    Qt Code:
    1. void Class::mousePressEvent( QMouseEvent *e )
    2. {
    3. //
    4. // Look at e->pos() to establish which corner is dragged and assign a value to
    5. // mResizeHandle
    6. //
    7. }
    8.  
    9. void Class::mouseMoveEvent( QMouseEvent *e )
    10. {
    11. // if mResizeHandle is eNone then nothing is resized
    12. switch( mResizeHandle )
    13. {
    14. case eTopLeft:
    15. // code to resize the object
    16. break;
    17. ...
    18. }
    19. }
    20.  
    21. void Class::mouseReleaseEvent( ... )
    22. {
    23. mResizeHandle = eNone;
    24. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to marcel for this useful post:

    elsheikhmh (10th April 2007)

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. QGraphicsItem and focus for key input
    By fossill in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2007, 19:13
  4. QGraphicsItem and signals
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 11:19
  5. Rotating QGraphicsItem
    By Gopala Krishna in forum Qt Programming
    Replies: 3
    Last Post: 21st December 2006, 11:50

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.