Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to time QPixmap::scaled?
Qt 6.11 is out! See what's new in the release blog

How to time QPixmap::scaled?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eligijus
    wrote on last edited by
    #1

    Hello,

    Is there an easy way to check/print how long QPixmap::scaled scaling with painting took?

    raven-worxR 1 Reply Last reply
    0
    • E Eligijus

      Hello,

      Is there an easy way to check/print how long QPixmap::scaled scaling with painting took?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Eligijus
      see QElapsedTimer class

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      E 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @Eligijus
        see QElapsedTimer class

        E Offline
        E Offline
        Eligijus
        wrote on last edited by
        #3

        @raven-worx QElapsedTimer on it's own does not give any meaningful results because of Qts Event system. I can clearly see that scaling takes longer than 1 ms but printing QElapsedTimer shows 0.

        raven-worxR 1 Reply Last reply
        0
        • E Eligijus

          @raven-worx QElapsedTimer on it's own does not give any meaningful results because of Qts Event system. I can clearly see that scaling takes longer than 1 ms but printing QElapsedTimer shows 0.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Eligijus
          can you please show how you used it.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          E 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @Eligijus
            can you please show how you used it.

            E Offline
            E Offline
            Eligijus
            wrote on last edited by
            #5

            @raven-worx

            label->setPixmap(myPixmap);
            label->setScaledContents(true);
            QElapsedTimer timer;
            timer.start();
            label->resize(size);
            qDebug() << timer.elapsed();
            
            J.HilkJ raven-worxR 2 Replies Last reply
            0
            • E Eligijus

              @raven-worx

              label->setPixmap(myPixmap);
              label->setScaledContents(true);
              QElapsedTimer timer;
              timer.start();
              label->resize(size);
              qDebug() << timer.elapsed();
              
              J.HilkJ Online
              J.HilkJ Online
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Eligijus
              I would do that slightly differen.

              //QElapsed timer as member and reimplementing a virtual function
              //In QLabel subclass
              public:
              void startTimer(){eTimer.start();}
              
              protected:
              QElapsedTimer eTimer;
              
              virtual void resizeEvent(QResizeEvent * event){
                 Q_Unused(event);
                 qDebug() << eTimer.elapsed();
              }
              
              //in your cpp
              label->setPixmap(myPixmap);
              label->setScaledContents(true);
              label->startTimer();
              label->resize(size);
              

              resizeEvent is called after the Widget has the new size e.g it should be painted than.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2
              • E Eligijus

                @raven-worx

                label->setPixmap(myPixmap);
                label->setScaledContents(true);
                QElapsedTimer timer;
                timer.start();
                label->resize(size);
                qDebug() << timer.elapsed();
                
                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #7

                @Eligijus said in How to time QPixmap::scaled?:

                @raven-worx

                label->setPixmap(myPixmap);
                label->setScaledContents(true);
                QElapsedTimer timer;
                timer.start();
                label->resize(size);
                qDebug() << timer.elapsed();
                

                exactly this won't work, because of the resize and paint event being executed in the next event loop iteration (after your timer.elapsed() call).

                Try the following to force a paint:

                label->setPixmap(myPixmap);
                label->setScaledContents(true);
                QElapsedTimer timer;
                timer.start();
                label->resize(size);
                label->repaint();
                qDebug() << timer.elapsed();
                

                Alternatively sub-class QLabel and simply override the paintEvent() like this:

                void MyLabel::paintEvent(QPaintEvent* event)
                {
                   QElapsedTimer timer;
                   timer.start();
                   QLabel::paintEvent(event);
                   qDebug() << timer.elapsed();
                }
                

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                4
                • E Offline
                  E Offline
                  Eligijus
                  wrote on last edited by
                  #8

                  Thanks sub-classing and overrinding paintevent method worked.

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved