move photo from right to left on widget
-
@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? -
@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
@camel-cn
And so? Maybe I do not understand, but you have aQTimer
moving something, which is what the animation framework does for you. Maybe it does not work fordrawImage()
, I'm not sure. Another possibility is to use aQGraphicsScene
instead, I don't know if that would "flicker" less than drawing on a widget. -
Hi,
How do you merge them ?
-
@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(); }
-
@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(); }
-
@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.
-
@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"
-
@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.
-
@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.