Results 1 to 17 of 17

Thread: Transformations on QGraphicsItem

  1. #1
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Transformations on QGraphicsItem

    Hi Guys,

    I am working on GraphicsScene and GraphicsItem classes. I have multiple graphics items on one GraphicsScene and want to apply transformations on the same. The idea is that whenever user clicks on a graphicsItem, the item should appear selected with some images on all corners to rotate and scale the item. I implemented another item class for this purpose and made it the parent of selected item.
    Now, as soon as the user clicks on corners of parent class, the item should be scaled and rotated.
    Any idea, how to achieve that?

    Regards,
    Manoj

  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: Transformations on QGraphicsItem

    Use QGraphicsItem::scale and QGraphicsItem::rotate to transform the item. But I wouldn't use any additional items for the selected state. You should implement that in the item itself by changing its painting routine.

  3. #3
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transformations on QGraphicsItem

    But it means that I implement same paint functionality for every item class I display on the scene?

  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: Transformations on QGraphicsItem

    Yes. But you can embed that functionality in another class or function and reuse it for each object class you use.

  5. #5
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transformations on QGraphicsItem

    I think this is not possible without having a parent item for those items as all the functionality in mouse events and paint event will have to be implemented to scale, rotate and translate the items.

  6. #6
    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: Transformations on QGraphicsItem

    Trust me, it's possible. What do you need a parent item for? You can do the scaling, rotating, etc. in the view or the scene.

  7. #7
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transformations on QGraphicsItem

    Well, I think I am really confused here then. Is it possible for you to give me some sample code if you have?

  8. #8
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Transformations on QGraphicsItem

    Try out the code mentioned in the blog
    http://labs.trolltech.com/blogs/2006...raphics-items/
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  9. #9
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transformations on QGraphicsItem

    Hmmmm...

    I have already tried it, the source code is not there.

  10. #10
    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: Transformations on QGraphicsItem

    What do you mean it's not there? Take a look at the implementation of the mouseMove event present there.

  11. #11
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Transformations on QGraphicsItem

    Quote Originally Posted by manojmka View Post
    Hmmmm...

    I have already tried it, the source code is not there.
    Yes , infact the source code tarball seems to be removed. I am attaching that for your reference, i hope Andreas doesn't mind.

    @admin and bitto: How about making this a wiki article ?
    Attached Files Attached Files
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  12. #12
    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: Transformations on QGraphicsItem

    Is there a point doubling what's already @ labs? Besides, there are no "discoveries" in the article Using scenePos() to calculate the origin is a natural thing to do

  13. #13
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Transformations on QGraphicsItem

    Quote Originally Posted by wysota View Post
    Is there a point doubling what's already @ labs? Besides, there are no "discoveries" in the article Using scenePos() to calculate the origin is a natural thing to do
    as you can see the articles/blogs are gradually lost and the new comers won't even know that somewhere some info is hidden in a great blog
    So atleast a link in the wiki can be mentioned and also "the natural thing" isn't quite obvious for newbies
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  14. #14
    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: Transformations on QGraphicsItem

    Feel free to make an article, as long as you don't violate any copyrights.

  15. #15
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transformations on QGraphicsItem

    Now, in the example attached everything i.e. scaling, rotation is done in mouseMoveEvent function of interactive item. I want the same interactions to be performed on different items like pixmap, text or rectangle. The item which has current mouse focus or grabbed should also appear with special images on all corners.

    Hope this makes the problem very clear this time?

  16. #16
    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: Transformations on QGraphicsItem

    But we don't see the problem - just draw those "special images" in your item in its paint() routine based on its state (like selected/not selected).

  17. #17
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Transformations on QGraphicsItem

    I think the problem was in my class design and it did not follow my all requirements. Anyways, I have now completely changed it and not using QGraphicsPixmapItem and QGraphicsTextItem. I have created my own pixmap and text item classes instead and inheriting them from my own GraphicsItem class.
    Thank you very much for all the support and time.

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 21:50
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 11:31
  3. rotation of an animated QGraphicsItem
    By darksaga in forum Qt Programming
    Replies: 9
    Last Post: 9th September 2007, 09:11
  4. Force the painting of a QGraphicsItem
    By fabietto in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 22:28
  5. QGraphicsItem and signals
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 12:19

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.