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. [SOLVED] Use QScollArea & QLabel to display image
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Use QScollArea & QLabel to display image

Scheduled Pinned Locked Moved General and Desktop
18 Posts 5 Posters 6.4k Views 4 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.
  • sheeleyS sheeley

    @mrjj Hi.
    Yes, I guess so.
    Is there any solution for this issue? I have a software, made by the video capture card manufacture, which is also written by Qt, it could work well. So I guess there should be a solution. Perhaps asynchronous refresh?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #6

    @sheeley
    Would it be an option just to show it scaled to screen so no scroll needed?

    Yeah, some sort of asynchronous refresh, or scolling.
    like after pix is set, its ok to scroll.
    Not sure how to program it though as you would need to capture the scroll event and
    check that setPixmap is not in progress and then scroll or or queue the scroll request and
    do the scrolling after setPixmap. But if you start to use a mutex or similar construct, you might end up skipping some frames.

    mrjjM 1 Reply Last reply
    1
    • mrjjM mrjj

      @sheeley
      Would it be an option just to show it scaled to screen so no scroll needed?

      Yeah, some sort of asynchronous refresh, or scolling.
      like after pix is set, its ok to scroll.
      Not sure how to program it though as you would need to capture the scroll event and
      check that setPixmap is not in progress and then scroll or or queue the scroll request and
      do the scrolling after setPixmap. But if you start to use a mutex or similar construct, you might end up skipping some frames.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #7

      Hi
      I wonder if you do
      bool oldState = mageLabel->blockSignals(true);
      mageLabel->setPixmap(QPixmap::fromImage(bmp));
      mageLabel->blockSignals(oldState);
      Would help as to block any scrolling request while "in there".
      Not sure it uses signals for that though.
      Fast to test.

      sheeleyS 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        I wonder if you do
        bool oldState = mageLabel->blockSignals(true);
        mageLabel->setPixmap(QPixmap::fromImage(bmp));
        mageLabel->blockSignals(oldState);
        Would help as to block any scrolling request while "in there".
        Not sure it uses signals for that though.
        Fast to test.

        sheeleyS Offline
        sheeleyS Offline
        sheeley
        wrote on last edited by
        #8

        @mrjj Thank you for your help. But it could not work... :(

        I like programming :)

        mrjjM 1 Reply Last reply
        0
        • sheeleyS sheeley

          @mrjj Thank you for your help. But it could not work... :(

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #9

          @sheeley

          I guess the paint event is not blocked
          so it happens anyway.
          Since the scrollbars tells scroll area to scroll and it then the label repaints itself.

          If you build your own widget and draw the image in the paintevent, it would be
          easier to make sure its not painting when being updated, I guess.

          Do you really need to scroll the image at 400 fps ?
          Its like preview of the stream?

          sheeleyS 1 Reply Last reply
          1
          • mrjjM mrjj

            @sheeley

            I guess the paint event is not blocked
            so it happens anyway.
            Since the scrollbars tells scroll area to scroll and it then the label repaints itself.

            If you build your own widget and draw the image in the paintevent, it would be
            easier to make sure its not painting when being updated, I guess.

            Do you really need to scroll the image at 400 fps ?
            Its like preview of the stream?

            sheeleyS Offline
            sheeleyS Offline
            sheeley
            wrote on last edited by
            #10

            @mrjj Yes. This window is for preview of the stream. The stream is received from a high speed camera, its feature is high speed, up to 400 fps - -!
            I will think about building my own widget. Could you please show me some examples, if convenient.
            Thank you for your patience. :)

            I like programming :)

            mrjjM 1 Reply Last reply
            0
            • sheeleyS sheeley

              @mrjj Yes. This window is for preview of the stream. The stream is received from a high speed camera, its feature is high speed, up to 400 fps - -!
              I will think about building my own widget. Could you please show me some examples, if convenient.
              Thank you for your patience. :)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #11

              @sheeley
              sketch code, fix to compile.
              Then if you lock the image when you set it and unlock
              when finished. and in paint check if ok to paint it.
              Something like that.

              class ImgPreview : public QWidget
              {
                  Q_OBJECT
                  
              public:
                  ImgPreview(QWidget *parent = 0) : QWidget(parent) {};
              
              protected:    
                  void paintEvent(QPaintEvent *event) {
                 QPainter p ( this );
                   if (ok_to_access_img)
                    p.drawImage(image);
                  }
              
              private:
                  void setImagePixel() {}
                  QImage image;
                  
              };
              
              sheeleyS 2 Replies Last reply
              1
              • mrjjM mrjj

                @sheeley
                sketch code, fix to compile.
                Then if you lock the image when you set it and unlock
                when finished. and in paint check if ok to paint it.
                Something like that.

                class ImgPreview : public QWidget
                {
                    Q_OBJECT
                    
                public:
                    ImgPreview(QWidget *parent = 0) : QWidget(parent) {};
                
                protected:    
                    void paintEvent(QPaintEvent *event) {
                   QPainter p ( this );
                     if (ok_to_access_img)
                      p.drawImage(image);
                    }
                
                private:
                    void setImagePixel() {}
                    QImage image;
                    
                };
                
                sheeleyS Offline
                sheeleyS Offline
                sheeley
                wrote on last edited by
                #12

                @mrjj OK. Thank you. If any questions, I'll keep in touch with you later.

                I like programming :)

                1 Reply Last reply
                0
                • mrjjM mrjj

                  @sheeley
                  sketch code, fix to compile.
                  Then if you lock the image when you set it and unlock
                  when finished. and in paint check if ok to paint it.
                  Something like that.

                  class ImgPreview : public QWidget
                  {
                      Q_OBJECT
                      
                  public:
                      ImgPreview(QWidget *parent = 0) : QWidget(parent) {};
                  
                  protected:    
                      void paintEvent(QPaintEvent *event) {
                     QPainter p ( this );
                       if (ok_to_access_img)
                        p.drawImage(image);
                      }
                  
                  private:
                      void setImagePixel() {}
                      QImage image;
                      
                  };
                  
                  sheeleyS Offline
                  sheeleyS Offline
                  sheeley
                  wrote on last edited by
                  #13

                  @mrjj Hi, I found some issues.
                  If I overwrite the paint function, when I drag the scrollbars, the window will stay unchanged. This will lead to an un-continuous feeling, yes?

                  I like programming :)

                  mrjjM 1 Reply Last reply
                  0
                  • sheeleyS sheeley

                    @mrjj Hi, I found some issues.
                    If I overwrite the paint function, when I drag the scrollbars, the window will stay unchanged. This will lead to an un-continuous feeling, yes?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #14

                    @sheeley
                    hi
                    set you widget , minimum size to the image size to it will reflect the image. then
                    scrolling works like with the QLabel and you can control when its safe to repaint.

                    sheeleyS 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @sheeley
                      hi
                      set you widget , minimum size to the image size to it will reflect the image. then
                      scrolling works like with the QLabel and you can control when its safe to repaint.

                      sheeleyS Offline
                      sheeleyS Offline
                      sheeley
                      wrote on last edited by
                      #15

                      @mrjj Hi.
                      I'm very excited now. I fixed it with defining a new signal and slot to do the refreshing work. The code is as follow: https://gist.github.com/tianshilei1992/fd76520532127deb28de
                      Done! The application won't crash, anymore! :)
                      Thank you for your patience yesterday.

                      I like programming :)

                      mrjjM 1 Reply Last reply
                      1
                      • sheeleyS sheeley

                        @mrjj Hi.
                        I'm very excited now. I fixed it with defining a new signal and slot to do the refreshing work. The code is as follow: https://gist.github.com/tianshilei1992/fd76520532127deb28de
                        Done! The application won't crash, anymore! :)
                        Thank you for your patience yesterday.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        @sheeley
                        Good work!
                        Thank you for update.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          phnhung98
                          wrote on last edited by
                          #17

                          Hi,
                          I followed your link but it is not available. I am interested in how you solved the problem. I am also trying to display video stream on QLabel with high framerate and large size of image. However, I suffer from screen tearing effect.
                          Thanks.

                          SGaistS 1 Reply Last reply
                          0
                          • P phnhung98

                            Hi,
                            I followed your link but it is not available. I am interested in how you solved the problem. I am also trying to display video stream on QLabel with high framerate and large size of image. However, I suffer from screen tearing effect.
                            Thanks.

                            SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #18

                            @phnhung98 said in [SOLVED] Use QScollArea & QLabel to display image:

                            Hi,
                            I followed your link but it is not available. I am interested in how you solved the problem. I am also trying to display video stream on QLabel with high framerate and large size of image. However, I suffer from screen tearing effect.
                            Thanks.

                            Hi and welcome to devnet,

                            Please define high speed and large size.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0

                            • Login

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