Results 1 to 11 of 11

Thread: QPixmap and QLabel performance

  1. #1
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QPixmap and QLabel performance

    I need to implement widget based on QToolButton that will allow display up to 4 icons on top of it. Icons will be moved, hidden, shown and changed. There will be many such widgets displayed at the same time and all of them will use same set of icons.
    I am worried about performance in this case, because I expect operations of loading graphics, moving it and hiding to be slow. For some reasons function that will arrange icons according to some set of variables will be called many times. Values of these variables not necessarily will be changed between consecutive calls, but we don't want to keep a copy of set of values during previous call of this function.

    I'm considering using 4 QLabels as containers for QPixmaps. I want to create static or global QPixmap variables, so I can create them once at start of application and use them to display icons simultanously on many such widgets. I have some questions related to this:

    1. Is QLabel::setPixmap() optimised so it does not cause refreshment of window after loading same QPixmap? Or should I always compare previous QPixmap in this label with the new to set?
    2. Are moving, hiding and displaying QLabels with QPixmaps slow operations? Should I check the position and visibility of QLabel to avoid situation, when I want to move QLabel to the current position or set visible already visible QLabel, to increase performance?

  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: QPixmap and QLabel performance

    I am worried about performance in this case, because I expect operations of loading graphics, moving it and hiding to be slow.
    this is not an issue if you use resources.
    Have a look at Qt resource system.
    http://doc.trolltech.com/4.7/resources.html
    This way the image files are compiled in to the exe and you don't have to worry about loading from disk.
    ==========================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
    Dec 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap and QLabel performance

    I know they are compiled in application.

    I'm sorry I was not very precise. I meant "displaying" instead of "loading" (calling functions show() and also hide()).

  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: QPixmap and QLabel performance

    know they are compiled in application.
    So why are you doing this for:
    I want to create static or global QPixmap variables, so I can create them once at start of application and use them to display icons simultanously on many such widgets.
    It looks to me you are not really aware of what resources are and how they are integrated in to the application - be sure to read the link I posted previously.

    I meant "displaying" instead of "loading" (calling functions show() and also hide()).
    Unless you are showing and hiding the images in a very high rate, (lets say less than 30 ms ) this should not be a problem.
    You are not showing video in your buttons are you?
    Just switching between images is neglectable as far as performance is concerned, on any relatively modern hardware.
    ==========================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
    Dec 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap and QLabel performance

    Quote Originally Posted by high_flyer View Post
    So why are you doing this for:

    It looks to me you are not really aware of what resources are and how they are integrated in to the application - be sure to read the link I posted previously.
    I must admit that I could not find detailed information about rendering images, creation of QPixmap objects etc. So I don't really understand how it works and don't know how to write optimised code.

    My application runs on embedded Linux, where performance is important. Architucture of this application has some weak points, but I can't change it at the moment. It runs slow already without any icons. So I would like to know if performance decreases when I call label.setPixmap(QPixmap(":/icons/icon.png")) many times in a row.

    By the way what format of picture would you advise in terms of performance? Png, gif, svg? Does it matter at all? I can just guess.

  6. #6
    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: QPixmap and QLabel performance

    Quote Originally Posted by mass85 View Post
    By the way what format of picture would you advise in terms of performance? Png, gif, svg? Does it matter at all? I can just guess.
    Once you load it, it doesn't matter. Just don't reload the same file again and again.
    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.


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

    mass85 (9th December 2010)

  8. #7
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap and QLabel performance

    I've changed my mind and now I don't want to compile all resources into application, but load them during runtime instead. According to my experiments I can't use static pointers to QPixmap as class members and create QPixmap objects just once in constructor of my class (load icons directly from disk), because application crashes. When these pointers are not static, application does not crash, but it's not a solution, becuase pixmaps are loaded every time we create another instance of this class.

    So I think I will have to use external resource file. I'm not sure if I know how to do it, some questions arise:

    1. After I create myresource.rcc file using
    Qt Code:
    1. rcc -binary myresource.qrc -o myresource.rcc
    To copy to clipboard, switch view to plain text mode 
    and load them in main() function before creating any windows:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QResource::registerResource("/path/to/myresource.rcc");
    5. MainWindow w;
    6. w.show();
    7.  
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 
    all icons will be accessible in the same way as they were compiled in application? This would mean that this code will work:
    Qt Code:
    1. myLabel.setPixmap(QPixmap(":/icons/icon.png"));
    To copy to clipboard, switch view to plain text mode 

    2. If I'm right about the above, I would like to automate the process of generating myresource.rcc. I guess that when I add myresource.qrc file to my project and build application, all resources are compiled in. I don't want them to be compiled in, but I want them to be accessible from my project in QT Creator. Is this possible?

    3. Anyway would you advise using files *.rcc or registering resources directly from files *.png?

    ===
    And some other important questions:
    4. If I load 3 pixmaps to 3 different labels in a row, when screen is refreshed (function Paint() or however it is named, is called)? Is it refreshed after each pixmap setting or optimised and refreshed just once?

    5. If I have 3 labels in some QLayout and I hide two of them, when will mechanism processing layouts start its work? After each single act of hiding or just once?

  9. #8
    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: QPixmap and QLabel performance

    In general have a look at QPixmapCache.
    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. #9
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap and QLabel performance

    QPixmapCache is an interesting solution, but could anyone answer to my questions? I answered to first question on my own by implementing and checking - it works as I thought. But rest of the questions are not so easy.

  11. #10
    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: QPixmap and QLabel performance

    2. Are moving, hiding and displaying QLabels with QPixmaps slow operations? Should I check the position and visibility of QLabel to avoid situation, when I want to move QLabel to the current position or set visible already visible QLabel, to increase performance?
    As in most situations the answer is "it depends on".

    all icons will be accessible in the same way as they were compiled in application?
    They will be accessible by paths you place them at in the resource file.

    2. If I'm right about the above, I would like to automate the process of generating myresource.rcc. I guess that when I add myresource.qrc file to my project and build application, all resources are compiled in. I don't want them to be compiled in, but I want them to be accessible from my project in QT Creator. Is this possible?
    Then they won't be resources anymore. What you want is access to files using a relative path. You don't need the resource system for that, just have a point of reference (like QCoreApplication::applicationDirPath()) and construct all paths based on that reference point.

    3. Anyway would you advise using files *.rcc or registering resources directly from files *.png?
    "it depends on".

    4. If I load 3 pixmaps to 3 different labels in a row, when screen is refreshed (function Paint() or however it is named, is called)? Is it refreshed after each pixmap setting or optimised and refreshed just once?
    It is refreshed when the control returns to the event loop and appropriate events scheduled by setting the pixmaps are processed (so if you assign 3 pixmaps one after the other, the widgets will be refreshed after all three pixmaps have already been set).

    5. If I have 3 labels in some QLayout and I hide two of them, when will mechanism processing layouts start its work? After each single act of hiding or just once?
    An event is scheduled for the layout to invalidate itself so when it is recalculated, both changes will be processed in one go.
    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.


  12. #11
    Join Date
    Dec 2010
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QPixmap and QLabel performance

    Quote Originally Posted by wysota View Post
    Then they won't be resources anymore. What you want is access to files using a relative path. You don't need the resource system for that, just have a point of reference (like QCoreApplication::applicationDirPath()) and construct all paths based on that reference point.
    I want to use resources, but load them from resources.rcc to my application when it starts, I don't want them to be build in application.

    The problem is just the way I generate resources.rcc file. I want this file to be generated from resources.qrc during compilation of application. If it is possible I want resources.qrc file to be visible in QT Creator project.

Similar Threads

  1. Replies: 11
    Last Post: 5th April 2010, 08:38
  2. QLabel, QPixmap and ScaledContents
    By mhbeyle in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2009, 09:11
  3. Rotate QPixmap set on QLabel
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2009, 12:08
  4. Replies: 2
    Last Post: 20th January 2009, 07:13
  5. performance issue(QGV + QPixmap::grabWidget)
    By momesana in forum Qt Programming
    Replies: 4
    Last Post: 27th September 2007, 11:31

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.