Results 1 to 6 of 6

Thread: Maximum Size of QPixmap/QImage Windows

  1. #1
    Join Date
    Oct 2010
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Maximum Size of QPixmap/QImage Windows

    I have a QGraphicsView for a very wide QGraphicsScene. I need to draw the background in drawBackground() and the background is a bit complicated (long loop) although it doesn't need to be repainted constantly. I store it in a static QPixmap (I tried QImage too) inside the function drawBackground() and that pixmap is what I draw onto the painter of the view. Only when needed is the QPixmap painted on again.

    If I didn't use a static pixmap, the complicated background would be generated every time I scroll sideways for example. The problem is that apparently there is a maximum width for pixmaps on Windows, on my computer it's 32770. I could store a list of pixmaps and draw them side by side but it would make the code uglier and I also don't know what the maximum width of a pixmap is for every Windows machine. Since this might be a well-known problem I was wondering if anyone has a better solution.


    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Maximum Size of QPixmap/QImage Windows

    If I didn't use a static pixmap, the complicated background would be generated every time I scroll sideways for example. The problem is that apparently there is a maximum width for pixmaps on Windows, on my computer it's 32770. I could store a list of pixmaps and draw them side by side but it would make the code uglier and I also don't know what the maximum width of a pixmap is for every Windows machine. Since this might be a well-known problem I was wondering if anyone has a better solution.
    Have a look at QPainter::drawTiledPixmap().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2010
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximum Size of QPixmap/QImage Windows

    Thanks, I didn't know about that. Although that only solves it for the part of the pixmap that stays the same, other part of the pixmap would change from tile to tile.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Maximum Size of QPixmap/QImage Windows

    Then there are two options I see:
    1. Don't use drawBackround, rather, put your pixmaps in items.
    That way, you don't waste memory, and let QGraphicsScene control which pixmaps are drawn (only the visible ones) -which is very efficient.
    2. Implement the visibility check on the pixmaps you self, and only draw the visible ones in drawBackground.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Oct 2010
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximum Size of QPixmap/QImage Windows

    Thanks again for answering. 1 would use more memory, what I can't use with tiled pixmaps because it changes is text and I'd prefer to avoid the overhead of having to use a qgraphicsitem for each piece of text of which there are many. I like 2 but I'm looking at the API and I don't see any function to get the visible area of the scene from the view.

    There is a scrollbar and sceneRect() would return the whole scene (the whole scene is visualized) but not the smaller Rect that is visible on screen when the function is called. I could get the value of the scrollbar and work from there but it would be cumbersome, isn't there any function that gets me that x coordinate I want? QWidget's visibleRegion doesn't work either.



    Ok I found the solution to my last question:

    QRect portRect = viewport()->rect();
    QRectF sceneRect = mapToScene(portRect).boundingRect();

    sceneRect.x() will have the coordinate I want.


    Thanks again
    Last edited by pssss; 11th February 2011 at 13:15.

  6. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximum Size of QPixmap/QImage Windows

    Hi!

    Use the exposedRect that a graphicsitem:aint function recieves. You will need to create an item for your background set its z order to a low number and implement your own caching method..

    Qt Code:
    1. CustomItem::CustomItem()
    2. {
    3. // Need this for exposedRect to be initialized!
    4. setFlag(QGraphicsItem::ItemUsesExtendedStyleOption,true);
    5. }
    6.  
    7. void CustomItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    8. {
    9. // Use the exposedRect
    10. option->exposedRect ..
    11. ..
    12. }
    To copy to clipboard, switch view to plain text mode 
    HIH

    Johannes

Similar Threads

  1. The maximum size of a QList
    By Denarius in forum Newbie
    Replies: 3
    Last Post: 30th November 2012, 10:27
  2. Replies: 6
    Last Post: 27th July 2010, 21:07
  3. maximum size of xml files
    By freeskydiver in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2008, 10:02
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11

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.