Results 1 to 11 of 11

Thread: QPixmap and QLabel performance

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


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

    mass85 (9th December 2010)

  4. #3
    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?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  6. #5
    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  8. #7
    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
  •  
Qt is a trademark of The Qt Company.