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. move photo from right to left on widget
Forum Updated to NodeBB v4.3 + New Features

move photo from right to left on widget

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 950 Views 2 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.
  • JonBJ JonB

    @camel-cn
    Although I have not used it, the usual way to do this in Qt is via The Animation Framework. If you try that does it improve?

    C Offline
    C Offline
    camel.cn
    wrote on last edited by
    #3

    @JonB sorry, I didn't make it clear; This is a simple demo; the initial requirement was to merge the received image slices and move them continuously from right to left on widget

    JonBJ 1 Reply Last reply
    0
    • C camel.cn

      @JonB sorry, I didn't make it clear; This is a simple demo; the initial requirement was to merge the received image slices and move them continuously from right to left on widget

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @camel-cn
      And so? Maybe I do not understand, but you have a QTimer moving something, which is what the animation framework does for you. Maybe it does not work for drawImage(), I'm not sure. Another possibility is to use a QGraphicsScene instead, I don't know if that would "flicker" less than drawing on a widget.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi,

        How do you merge them ?

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

        C 1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #6

          @camel-cn said in move photo from right to left on widget:

          try the following:

          void Widget::paintEvent(QPaintEvent* event)
          {
              Q_UNUSED(event);
              QPainter painter(this);
              painter.setRenderHint(QPainter::Antialiasing);
              painter.save();
          
              auto w = this->width();
              auto h = this->height();
          
              auto imgw = this->_img.width(); //_img is QImage
              auto imgh = this->_img.height();
          
              if(this->_pos >= imgw) this->_pos = 0;
          
              this->_pos += 10; // init 0
          
              if(this->_pos >= imgw) this->_pos = imgw;
          
              auto x = (w - this->_pos) / 2.0;
              auto y = (h - imgh) / 2.0;
          
              painter.drawImage(QPointF(x, y), _img, QRectF(0, 0, this->_pos, imgh));
             
              painter.restore();
          }
          
          C 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            How do you merge them ?

            C Offline
            C Offline
            camel.cn
            wrote on last edited by
            #7

            @SGaist Mainly through the function drawImage of QPainter

            SGaistS 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @camel-cn said in move photo from right to left on widget:

              try the following:

              void Widget::paintEvent(QPaintEvent* event)
              {
                  Q_UNUSED(event);
                  QPainter painter(this);
                  painter.setRenderHint(QPainter::Antialiasing);
                  painter.save();
              
                  auto w = this->width();
                  auto h = this->height();
              
                  auto imgw = this->_img.width(); //_img is QImage
                  auto imgh = this->_img.height();
              
                  if(this->_pos >= imgw) this->_pos = 0;
              
                  this->_pos += 10; // init 0
              
                  if(this->_pos >= imgw) this->_pos = imgw;
              
                  auto x = (w - this->_pos) / 2.0;
                  auto y = (h - imgh) / 2.0;
              
                  painter.drawImage(QPointF(x, y), _img, QRectF(0, 0, this->_pos, imgh));
                 
                  painter.restore();
              }
              
              C Offline
              C Offline
              camel.cn
              wrote on last edited by
              #8

              @JoeCFD said in move photo from right to left on widget:

              QPainter::Antialiasing

              QPainter::Antialiasing at here does't work for improve phenomenon, but reducing the move step size can improve the "flicker"

              JoeCFDJ 1 Reply Last reply
              0
              • C camel.cn

                @SGaist Mainly through the function drawImage of QPainter

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

                @camel-cn said in move photo from right to left on widget:

                @SGaist Mainly through the function drawImage of QPainter

                You move your image in that function, it does not look like you do any merging there.

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

                C 1 Reply Last reply
                0
                • C camel.cn

                  @JoeCFD said in move photo from right to left on widget:

                  QPainter::Antialiasing

                  QPainter::Antialiasing at here does't work for improve phenomenon, but reducing the move step size can improve the "flicker"

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #10

                  @camel-cn Right. Slowing your timer down will help and it is unnecessary to update the image quickly. I simply showed how painter is used in my app.

                  C 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @camel-cn said in move photo from right to left on widget:

                    @SGaist Mainly through the function drawImage of QPainter

                    You move your image in that function, it does not look like you do any merging there.

                    C Offline
                    C Offline
                    camel.cn
                    wrote on last edited by
                    #11

                    @SGaist The initial requirement was to merge the received image slices and move them continuously from right to left on widget,However, this code is a simple demo for moving image;

                    1 Reply Last reply
                    0
                    • JoeCFDJ JoeCFD

                      @camel-cn Right. Slowing your timer down will help and it is unnecessary to update the image quickly. I simply showed how painter is used in my app.

                      C Offline
                      C Offline
                      camel.cn
                      wrote on last edited by
                      #12

                      @JoeCFD Thank you for your help

                      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