Results 1 to 8 of 8

Thread: Image rendering and zooming (QGraphicsView)

  1. #1
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Image rendering and zooming (QGraphicsView)

    Hello,

    I am currently displaying audio waveforms and spectrograms in my app and I need to be able to zoom in and out of these images and have the best possible resolution in each level of zoom. For the display I am using the Qt Graphics Framework.

    I am a bit lost on how to approach this problem, I think that I have to keep several images of different zoom levels in memory and change them according to how much I zoom in ..? What is the proper way of tackling this issue?

    Any guidance or tips for what would be the best Qt tools or methods to use to get started I would really appreciate it!

    Thanks.

  2. #2
    Join Date
    Sep 2011
    Location
    Mannheim, Germany
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    use this in MygraphicsItem:aint() method.
    qreal levelOfDetail = QStyleOptionGraphicsItem::levelOfDetailFromTransfo rm(painter->transform());

    if(levelOfDetail <= 0.5)
    {
    drawMyLowResImage();
    }
    else
    {
    drawMyHighResImage();
    }


    You only need to draw the visible part of your image.
    const QRectF& rect = option->exposedRect;

    painter->transform() corresponds to your qgraphicsView zoomLevel.

  3. #3
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    Maybe QGraphicsView::scale(qreal sx, qreal sy) can help.
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  4. #4
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    Quote Originally Posted by woodtluk View Post
    Maybe QGraphicsView::scale(qreal sx, qreal sy) can help.
    Well scale is what I was using at first to zoom in and out, but that just scales an image so when zoomed in, the image is very pixelated especially at high zoom levels. So I'm looking for a way to
    change the image to a better resolution one after it hits a certain level of zoom, and so on for several levels (and then back when zooming out). For now I am just zooming in width so for example
    after a zoom I want to just have a higher resolution image of just the exposed part of the image.

  5. #5
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    You need Scalable Vector Graphics(SVG) format images. Normal images will become pixelated at high zoom levels. Qt supports svg images too.

  6. The following user says thank you to pkj for this useful post:

    Sergex (6th October 2011)

  7. #6
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    Quote Originally Posted by dennis81 View Post
    use this in MygraphicsItem:aint() method.
    qreal levelOfDetail = QStyleOptionGraphicsItem::levelOfDetailFromTransfo rm(painter->transform());

    if(levelOfDetail <= 0.5)
    {
    drawMyLowResImage();
    }
    else
    {
    drawMyHighResImage();
    }


    You only need to draw the visible part of your image.
    const QRectF& rect = option->exposedRect;

    painter->transform() corresponds to your qgraphicsView zoomLevel.
    Thanks! That gives me some ideas, as of now when my graphicsItem was created I was passing the image as a parameter to the graphicsItem. But will try some things with this idea, thanks.

  8. #7
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    Quote Originally Posted by pkj View Post
    You need Scalable Vector Graphics(SVG) format images. Normal images will become pixelated at high zoom levels. Qt supports svg images too.
    Is it possible to transform my Images into Svg format somehow ? That definitely would be better as of now the images are Indexed8 kind. Thanks for the tip!

  9. #8
    Join Date
    Sep 2011
    Location
    Mannheim, Germany
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image rendering and zooming (QGraphicsView)

    It would be easier render the waveforms as QPolygonItems.
    Converting raster images into vector images is problematic.


    Could you upload a screen shot?

Similar Threads

  1. How to zooming like in AutoCAD with QGraphicsView?
    By Tarhan in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2011, 09:16
  2. Zooming image
    By MTK358 in forum Qt Programming
    Replies: 18
    Last Post: 27th September 2010, 19:25
  3. Questions about zooming QGraphicsView
    By JovianGhost in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2010, 15:54
  4. Zooming is too slow with QGraphicsView
    By learning_qt in forum Qt Programming
    Replies: 10
    Last Post: 4th December 2008, 10:23
  5. Zooming in QGraphicsView
    By JonathanForQT4 in forum Newbie
    Replies: 3
    Last Post: 17th April 2007, 06:50

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.