Results 1 to 5 of 5

Thread: widget re-use, style sheets, and memory usage

  1. #1
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default widget re-use, style sheets, and memory usage

    Hi,

    We've written an application that uses style sheets to "skin" buttons, etc., using PNG files. There are multiple instances where we re-use widgets (i.e., have multiple instances of the same kind of widget) where each instance must have the style sheet "re-declared" due to the widget hierarchy. Is there any way to make widgets whose style sheets point to the same image "share" one single pixmap within memory?

    I see Qt has "implicit data sharing," but I struggle to figure out any easy way to leverage it for style pixmaps while using style sheets.

    Any help would be much appreciated! Thanks!

    -Ray Froehlich

  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: widget re-use, style sheets, and memory usage

    I think Qt for stylesheets uses a pixmap cache in the background so all buttons using the same images should in fact use the same pixmap.
    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.


  3. #3
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: widget re-use, style sheets, and memory usage

    First of all, thank you for the quick response. I really do appreciate it!

    Are you sure about the pixmap cache? That was my assumption as well, but all the data I've collected so far indicates this is not the case. Or, is there something I need to do to leverage this cache that I may not be doing now?

    Looking at the Qt source code 4.6.1, QRenderRule constructor, it looks like a regular QPixmap is constructed when the bg member of type QStyleSheetBackgroundData is instantiated.

    Thanks again for the help!

    -Ray

  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: widget re-use, style sheets, and memory usage

    Quote Originally Posted by Ray Froehlich View Post
    Are you sure about the pixmap cache?
    No, but it would be silly of the Trolls not to do it this way. I don't want to dig into Qt code right now so I can't be certain.

    That was my assumption as well, but all the data I've collected so far indicates this is not the case.
    If you mean that the more widgets you have the more memory is used this proves nothing. Surely each button has its own instance of the final pixmap associated with it but it doesn't mean the intermediate pixmaps are not shared between instances.

    Looking at the Qt source code 4.6.1, QRenderRule constructor, it looks like a regular QPixmap is constructed when the bg member of type QStyleSheetBackgroundData is instantiated.
    You should look into QPixmap code as well.
    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.


  5. #5
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: widget re-use, style sheets, and memory usage

    I agree, it would be silly. Also, I can't blame you for not wanting to dig into Qt source code. Finally, thanks for the QPixmap suggestion. I'll take a look.

    If anyone else has anything to add, please feel free.

Similar Threads

  1. Style Sheets
    By yakuzan in forum Newbie
    Replies: 5
    Last Post: 29th May 2010, 09:11
  2. Do Qt Style Sheets support List-style-image?
    By daiheitan in forum Qt Programming
    Replies: 6
    Last Post: 12th March 2010, 01:41
  3. Memory usage problem when setting style sheet
    By DiamonDogX in forum Qt Programming
    Replies: 12
    Last Post: 18th November 2009, 15:52
  4. style sheets
    By alisami in forum Qt Programming
    Replies: 8
    Last Post: 7th May 2009, 09:41
  5. Replies: 6
    Last Post: 14th April 2009, 17:40

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.