Skip to content

Instantly share code, notes, and snippets.

@vladon
Created May 18, 2015 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladon/d02ae31690cc2fa8a8fa to your computer and use it in GitHub Desktop.
Save vladon/d02ae31690cc2fa8a8fa to your computer and use it in GitHub Desktop.
Transition from Qt4 to Qt5: one overloaded version of QPainter:drawPixmapFragments absent in Qt5
void drawPixmapFragments(QPainter *painter, const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount,
const QPixmap &pixmap, QPainter::PixmapFragmentHints hints)
{
for (int i = 0; i < fragmentCount; ++i) {
QRectF sourceRect = (sourceRects) ? sourceRects[i] : pixmap.rect();
QPainter::PixmapFragment pixmapFragment =
QPainter::PixmapFragment::create(
targetRects[i].center(),
sourceRects[i],
targetRects[i].width() / sourceRect.width(),
targetRects[i].height() / sourceRect.height()
);
painter->drawPixmapFragments(&pixmapFragment, 1, pixmap, hints);
}
}
@vladon
Copy link
Author

vladon commented May 18, 2015

In Qt5 the function QPainter::drawPixmapFragments with five arguments was deprecated:

void QPainter::drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount,
const QPixmap &pixmap, QPainter::PixmapFragmentHints hints)

This function does not exists in Qt5.

This gist is the helper for transition, call it as before in Qt4, but first parameter is the pointer to your QPainter instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment