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. Moving QLabel on QCameraViewfinder will blink

Moving QLabel on QCameraViewfinder will blink

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 2.2k Views
  • 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.
  • C Offline
    C Offline
    CYLee
    wrote on last edited by
    #1

    Dear Qt experts,

    I used QT example "camera" to add a QLabel on the QCameraViewfinder.
    And I used the Horizontal Slider and setGeometry to change the QLabel position.
    The problem is, when the video active and I operate the slider.
    The QLabel will blink when it moving.
    Can someone tell me how to improve it?
    Thanks.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can try subclass QCameraViewfinder and override its paintEvent.
      Then in paintevent call base paint
      and then draw your text.
      That should prevent flickering.
      Sadly i dont have any camera so i cant tell if it will work.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CYLee
        wrote on last edited by
        #3

        @mrjj thank you for your reply.
        I'm new in QT and C++.
        So...could you be a bit more specific about implementation?
        And I found the same problem when I import a png image on the QCameraViewfinder.
        Should I use the same way to improve it?
        Thank you.

        mrjjM 1 Reply Last reply
        0
        • C CYLee

          @mrjj thank you for your reply.
          I'm new in QT and C++.
          So...could you be a bit more specific about implementation?
          And I found the same problem when I import a png image on the QCameraViewfinder.
          Should I use the same way to improve it?
          Thank you.

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

          @CYLee

          Hi
          I wish i had a camera so i could test it fast but lets talk about the terms

          Subclassing:
          Make your own class based on other class

          class MyCameraViewfinder : public QCameraViewfinder {
            Q_OBJECT
          public:
              explicit MyCameraViewfinder(QWidget* parent = nullptr) : QCameraViewfinder(parent) {     
              }
          protected:
            virtual void paintEvent(QPaintEvent* event) override { // override a base function with own
              // Default rendered -> call base class
              QCameraViewfinder::paintEvent(event);
             // draw some text
               QPainter painter(this);
                painter.drawText(100,100,"text");
             };
          };
          
          

          You then use your instead of the default one.
          You can new it and place it yourself or use promotion feature
          http://doc.qt.io/qt-5/designer-using-custom-widgets.html
          which makes it easy to use in Designer / the camera sample.
          (it already use promotion that sample)

          Anyway, i test with camera sample and i think it will work but
          since i cant see with camera on, i cant not know 100%

          alt text

          Changed project with custom widget.
          https://www.dropbox.com/s/r25lqvmj3lqimhg/camdraw.zip?dl=0

          To move it around, you just make the x,y of the drawtext variable/properties and
          then change those.

          1 Reply Last reply
          1
          • C Offline
            C Offline
            CYLee
            wrote on last edited by
            #5

            @mrjj thank you for your reply again.

            How can I change drawtext variable/properties via slider or button?

            I declared a variable and tried to change that value via Horizontal Slider.

            But it doesn't work.

            mrjjM 1 Reply Last reply
            0
            • C CYLee

              @mrjj thank you for your reply again.

              How can I change drawtext variable/properties via slider or button?

              I declared a variable and tried to change that value via Horizontal Slider.

              But it doesn't work.

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

              @CYLee
              you the
              100,100 in drawText need to be changed.

              Can you show what you tried and "didnt work"?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CYLee
                wrote on last edited by
                #7

                @mrjj

                I'm sorry that I did not describe it well.

                I declared a variable drawText_x and change that value via Horizontal Slider.

                mycameraviewfinder.h
                
                class MyCameraViewfinder : public QCameraViewfinder {
                    Q_OBJECT
                public:
                    explicit MyCameraViewfinder(QWidget* parent = nullptr) : QCameraViewfinder(parent) {
                    }
                
                    int drawText_x;
                
                protected:
                    virtual void paintEvent(QPaintEvent* event) override { // override a base function with own
                        // Default rendered -> call base class
                        QCameraViewfinder::paintEvent(event);
                        // draw some text
                        QPainter painter(this);
                        painter.drawText(drawText_x, 100, "this is my text");
                    }
                };
                
                camera.cpp
                void Camera::on_horizontalSlider_valueChanged(int value)
                {
                    MyCameraViewfinder m;
                    m.drawText_x = value;
                }
                

                0_1514211789580_圖片 1.png

                As you can see, the string disappeared.

                I set a breakpoint to trace drawText_x, the value didn't change.

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  Hi
                  with 100,100 fixed value, is the string there ?
                  Just checking the idea works at all :)

                  Regardless
                  void Camera::on_horizontalSlider_valueChanged(int value)
                  {
                  MyCameraViewfinder m; <<< local value, and other copy. not the one on screen
                  m.drawText_x = value;
                  } // dead here also

                  the one in sample is changed to MyCameraViewfinder

                  so it should be
                  void Camera::on_horizontalSlider_valueChanged(int value)
                  {
                  ui->viewfinder-> drawText_x = value; // drawText_x is public.
                  }

                  1 Reply Last reply
                  2
                  • C Offline
                    C Offline
                    CYLee
                    wrote on last edited by
                    #9

                    @mrjj

                    Problem solved!

                    You really helped me a lot.

                    Thank you for the detailed reply.

                    mrjjM 1 Reply Last reply
                    1
                    • C CYLee

                      @mrjj

                      Problem solved!

                      You really helped me a lot.

                      Thank you for the detailed reply.

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

                      @CYLee
                      You are welcome. Glad it did work as i hoped and camera feed not drawn
                      as overlay on widget :)

                      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