Created
January 27, 2015 02:34
-
-
Save Goddard/44cdc35ca8e9807e384c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ImageView::paintEvent(QPaintEvent*) | |
{ | |
if (this->imageBuffer.empty()){ return; } | |
double widgetWidth = this->width(); | |
double widgetHeight = this->height(); | |
QRectF target(0, 0, widgetWidth, widgetHeight); | |
QImage tempQImage = *this->imageBuffer.at(this->imageBuffer.count()-1); | |
tempQImage = tempQImage.scaled(rect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); | |
double imageSizeWidth = static_cast<double>(tempQImage.width()); | |
double imageSizeHeight = static_cast<double>(tempQImage.height()); | |
QRectF source(0.0, 0.0, imageSizeWidth, imageSizeHeight); | |
int deltaX = 0; | |
int deltaY = 0; | |
if(source.width() < target.width()) | |
deltaX = target.width() - source.width(); | |
else | |
deltaX = source.width() - target.width(); | |
if(source.height() < target.height()) | |
deltaY = target.height() - source.height(); | |
else | |
deltaY = source.height() - target.height(); | |
QPainter painter(this); | |
painter.translate(deltaX / 2, deltaY / 2); | |
painter.drawImage(source, tempQImage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment