Results 1 to 11 of 11

Thread: Zooming is too slow with QGraphicsView

  1. #1
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Zooming is too slow with QGraphicsView

    I load a big picture into QGraphicsView. Then I zoom it to 3x. But it is too slow. Are there some solutions to this problem.

    I have to use QImage format in my case.

  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: Zooming is too slow with QGraphicsView

    Divide the image into smaller pieces.

  3. #3
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Zooming is too slow with QGraphicsView

    Thanks!

    How can divide? Then I need to arrange those small images in a certain order. Could you please give some examples?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Zooming is too slow with QGraphicsView

    Hi,

    Have you tried to use OpenGL on the viewport?
    Òscar Llarch i Galán

  5. #5
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Zooming is too slow with QGraphicsView

    No, I have not tried OpenGL for zooming in QGraphicsView.
    When I run OpenGL examples with Ubuntu, I always have the problem:
    Xlib: extension "GLX" missing on display ":0.0".
    How can I resolve it?

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Zooming is too slow with QGraphicsView

    Hi,

    You have to install GLX for X Window. It is the openGL eXtension for X Window System.
    Òscar Llarch i Galán

  7. #7
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Zooming is too slow with QGraphicsView

    Thanks!

    I have installed libgl1-mesa-glx and nvidia-glx. But the problems is still there. what else libs should i install?

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Zooming is too slow with QGraphicsView

    Hi,

    You have installed GLX but I think that you don't have X Window configured to use it. I really don't know how to activate it but you can search it on the web.
    Òscar Llarch i Galán

  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: Zooming is too slow with QGraphicsView

    Quote Originally Posted by learning_qt View Post
    Thanks!

    How can divide? Then I need to arrange those small images in a certain order. Could you please give some examples?
    Yes, you then need to arrange items but this is trivial so it should take you no more than 2 minutes to do it - load your image and create items from it where each item contains a 200x200 block of pixels, then set position of the images according to their offsets from the top left corner of the image.

    You experience slowdowns because zooming causes your image to be scaled while being painted and because the image is big, it takes time. Furthermore as you zoom in closer and closer, regions of the image are moved out of the viewport but as the image is still one big item, the whole item (hence the whole image) has to be repainted. Dividing into tiles yields two benefits - items scale faster and there are less items to draw as those that move out of the viewport are ignored while updating the view.


    Quote Originally Posted by ^NyAw^ View Post
    Hi,

    Have you tried to use OpenGL on the viewport?
    This won't change much.

    Edit:
    Here is something to play with. If you compile it with OpenGL support (qmake QT+=opengl) it will use the OpenGL viewport. Run it without parameters to see the usage help. In general it gives quite nice results for me, the scrolling is smooth while the image is zoomed in. I tested it using images roughly 2000x2000 in size but for bigger images the gain should be even bigger (at the expense of memory usage).
    Attached Files Attached Files
    Last edited by wysota; 4th December 2008 at 00:38. Reason: Added the file archive

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

    learning_qt (4th December 2008)

  11. #10
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Zooming is too slow with QGraphicsView

    Thanks!

    But there is still one problem. When I zoom out, there are always white lines among tiles. I suppose those areas are not covered.

    How can we resolve this problem?

  12. #11
    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: Zooming is too slow with QGraphicsView

    You have to implement your own pixmap item. I guess the effect is caused by how QRect works or rounding problems. Providing your own proper implementation of a pixmap item should fix the problem. At worst you can use a bigger overlap between items (I used 1x1 overlap which already helped, if you use 2x2 it should be much better).

Similar Threads

  1. QGraphicsView Problem
    By hakkman in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2008, 20:27
  2. Slow painting in QGraphicsView
    By JonathanForQT4 in forum Qt Programming
    Replies: 12
    Last Post: 16th July 2007, 09:54
  3. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14
  4. Zooming in QGraphicsView
    By JonathanForQT4 in forum Newbie
    Replies: 3
    Last Post: 17th April 2007, 05: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.