Results 1 to 10 of 10

Thread: Scaling QGraphicsPixmapItem

  1. #1
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Scaling QGraphicsPixmapItem

    I am trying to create a multitouch gametable application. I have been trying to use a QGraphicsScene with a QGraphicsView for the gametable. I will be allowing users to add maps and create maps. What is the best way to add QGraphicsPixmapItems and allow users to scale and rotate the image without affecting performance. I have noticed that if I just apply a transformation matrix to the QGraphicsPixmapItem the rendering of the image takes a really long time. I have tried adjusting the cache mode but it doesn't allow me to adjust the transformation matrix.

    Does anyone have a better idea for transforming pixmaps?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QGraphicsPixmapItem

    Cant answer your question, but probably I have a question for you...
    How do you use multi touch ? am curious abt its implementation..

  3. #3
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QGraphicsPixmapItem

    I haven't got too far with the implementation of the multitouch. I am using the TUIO library from tuio.org which connects over udp to any multitouch server that supports the TUIO protocol. The TUIO protocol sends messages for when a cursor is created, moved, and then removed and it also support fiducial markers. Right now I am trying to create a simple app similar to the picture apps you see demonstrated that allows you to moved, rotate and resize images.

  4. #4
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QGraphicsPixmapItem

    I should have posted the code I am using.

    Qt Code:
    1. scene.setSceneRect(0,0,5000,5000)
    2.  
    3. QGraphicsPixmapItem testImage(QPixmap("./MOATHOUSE-FINAL.jpg"));
    4. scene.addItem(&testImage);
    5. testImage.scale(.5,.5);
    6.  
    7. QGraphicsView view(&scene);
    8. view.showMaximized();
    9. view.setBackgroundBrush(Qt::black);
    To copy to clipboard, switch view to plain text mode 

    When I scroll the view to where the image is located scrolling becomes very choppy. I have tried both
    Qt Code:
    1. testImage.setCacheMode(QGraphicsItem::ItemCoordinateCache,QSize((testImage.boundingRect().width(),testImage.boundingRect().height()));
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. testImage.setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    To copy to clipboard, switch view to plain text mode 

    Setting the cache mode works until I change the scale again and then scrolling the view is slow again when the pixmap is displayed.

  5. #5
    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: Scaling QGraphicsPixmapItem

    How big is the image?
    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.


  6. #6
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QGraphicsPixmapItem

    My image is 4000x3800

  7. #7
    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: Scaling QGraphicsPixmapItem

    Don't expect miracles then. Scaling such an image takes time and this has to be done every time the transformation of your item changes. You can improve performance by cutting the image into smaller pieces and composing them into your large picture.
    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.


  8. #8
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QGraphicsPixmapItem

    Quote Originally Posted by wysota View Post
    You can improve performance by cutting the image into smaller pieces and composing them into your large picture.
    That is the next solution I was going to try. Do you know of any example programs that do that?

  9. #9
    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: Scaling QGraphicsPixmapItem

    Quote Originally Posted by johnsoga View Post
    That is the next solution I was going to try. Do you know of any example programs that do that?
    As far as I remember there is an example implementation of mine somewhere in this forum but it might be hard to find.
    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.


  10. The following user says thank you to wysota for this useful post:

    johnsoga (7th May 2009)

  11. #10
    Join Date
    May 2009
    Posts
    16
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scaling QGraphicsPixmapItem

    Okay, I will look around the forums. Thanks for the help

Similar Threads

  1. Replies: 8
    Last Post: 12th March 2009, 14:12
  2. Replies: 3
    Last Post: 2nd February 2009, 23:40
  3. Scaling Painter without scaling the coordinate sytem
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2008, 21:30
  4. Ignoring scaling graphics view/scale
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 17:44
  5. Replies: 12
    Last Post: 25th May 2006, 21:12

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.