Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Loading images or draw them?? witch one is faster?



  • So, I'd like to make some custom widgets for weather application and I just wish to know what is the best option to do them and how... by using QPainter and start painting the object or by using a png image with QPixmap?


  • Lifetime Qt Champion

    A QPixmap must also be painted ... so what should be the difference? If you want to draw a picture you must first load it or paint it by yourself. Painting the image directly in the paintEvent will for sure take more time - esp. since the image won't change as often as paintEvent is (maybe) called I would guess.



  • hmm... that is bed news for me... I do prefer to design things in Krita or Inkscape... but to draw them in C++... that is another story.. how can I draw a moon?? what to use to do it?? just a normal white moon-shape


  • Lifetime Qt Champion

    Hi,

    How many times per second do you expect your application to refresh its content ?

    How big are your images ?

    One possibility is also to compose a QPixmap with the various information you want and put it in a QLabel to be shown.


  • Moderators

    @arsinte_andrei said in Loading images or draw them?? witch one is faster?:

    I just wish to know what is the best option to do them and how...

    The best option is usually the simplest option. Don't worry about which one is "faster" unless the simplest option causes problems.

    @arsinte_andrei said in Loading images or draw them?? witch one is faster?:

    I do prefer to design things in Krita or Inkscape... but to draw them in C++... that is another story.. how can I draw a moon?? what to use to do it?? just a normal white moon-shape

    In this case, you should use Krita and Inkscape to draw your moon.

    that is bed news for me...

    Why is it bad news? Loading a .png image is a perfectly good approach.



  • this is what I wish to build up is Qt c++ (sorry no Qt quick as I have no idea what is it and how to use it - I have more control in c++ where I can implement all the animation that I need)

    0_1561237989937_claydons.png

    the refresh rate is set to about 1 minute so... and is a weather station running on raspberry pi
    (BTW if anyone is interested in the project I do offer it for free GPL2/3 not decided yet)
    is to control smart home systems - written in Qt and cloudless (you can add cloud if you want) freedom is the core of it...

    anyway enough with advertising.. now, how do you recommend to do it??
    in my opinion I'm trying to do something similar at look to it - and with each widget to receive its own data and to represent it


  • Lifetime Qt Champion

    Hi
    is this for a desktop application or a mobile one? (or both)


  • Lifetime Qt Champion

    Go with @JKSH's suggestions. Just take into account that you don't need super high definitions of your images unless you are driving a 4k screen which is unlikely with a current RPi.



  • @mrjj
    is for raspberry pi with the 7" display
    so basically I'm using a raspberry pi in each room as the main controller: from here you can access all the info like audio, weather, lights, blinds, etc...
    In the house is also a server that communicates with all the sensors and reply back to the raspberry pi



  • @arsinte_andrei said in Loading images or draw them?? witch one is faster?:

    hmm... that is bed news for me... I do prefer to design things in Krita or Inkscape... but to draw them in C++... that is another story.. how can I draw a moon?? what to use to do it?? just a normal white moon-shape

    It sounds like there may have been a miscommunication if you feel that you've gotten bad news. The act of taking an image loaded into memory and putting it on screen is called "painting" and you use QPainter to do it. Regardless of whether you are drawing lines and circles using the API, or copying a buffer from a pixmap that started out as a PNG image.

    As for the fastest way to do it... Just start with the simplest way, and see if that's fast enough. Only worry about solving the problems you have. A Raspberry Pi is obviously a lot slower than a desktop system so you are more likely to run into performance problems there. But it makes more sense to start with a simple prototype, and profile what the slow parts are, rather than worry about things you imagine could potentially be slow and spend your time working on stuff that may not actually have been a problem.


Log in to reply