Results 1 to 4 of 4

Thread: QGraphicsItem move only on certain condition

  1. #1
    Join Date
    Mar 2012
    Location
    India
    Posts
    22
    Thanks
    3
    Qt products
    Qt4

    Default QGraphicsItem move only on certain condition

    I have an application (consider something like paint) where in I create custom QGraphicsItem ( assume something similar to a rectangle for understanding the problem). There is a functionality where in the user can resize the QGraphicsItem, but the item must maintain some aspect ratio. (i.e. for eg. the height of the rectangle cannot be greater than half its width).

    For resizing I create 4 QGraphicsItem object which are positioned at the four corners. Clicking on the resize rects and dragging the mouse resizes the associated QGraphicsItem.
    Now on clicking any resize rects the resizing starts and the size of the QGraphicsItem changes according to the mouse move while maintaining the aspect ratio.
    So for the rectangle after the height is equal to half its width the size of the QGraphicsItem doesn't change for any mouse move in vertical direction ( i.e. the height of the QGraphicsItem wont change on dragging the mouse vertically down).

    But my problem is that when I move the mouse vertically down after the rectangle has height is equal to half its width the resize rect should still stay at the corner of the QGraphicsItem.
    Currently it moves along with the mouse.
    Is there any way to achieve it ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem move only on certain condition

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2012
    Location
    India
    Posts
    22
    Thanks
    3
    Qt products
    Qt4

    Default Re: QGraphicsItem move only on certain condition

    Thanks for quick reply.

    But I have another problem that how will the resize rect objects know about the aspect ratio being maintained. Maintaining the aspect ratio is the property of the associated QGraphicsItem. So how will the item change know that what position to consider invalid.
    If I use the item change of the custom QGraphicsItem and set the resize points position on geometry change would still lead to the same issue.

    Maybe will need to change the architecture. Is there any other solution ??

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem move only on certain condition

    "Teach" your handle objects about it. Or use itemChange() on the main object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsItem move
    By Ichi in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2013, 19:48
  2. Overload QGraphicsItem Move in Scene
    By D Cell in forum Newbie
    Replies: 2
    Last Post: 16th March 2010, 05:14
  3. QGraphicsItem Horizontal/Vertical move only
    By prashant in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 09:02
  4. how to prevent qgraphicsitem repaint while mouse move on it
    By christina123y in forum Qt Programming
    Replies: 22
    Last Post: 17th April 2009, 10:17
  5. QGraphicsItem move question
    By mhoover in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2006, 19:01

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.