c++ - Qt4 to Qt5: QPainter::drawPixmapFragments() with 5 arguments - how to solve? (Updated) -


qt 4.8 (4.8.6) has qpainter::drawpixmapfragments() overloaded function 5 arguments:

void drawpixmapfragments(const qrectf *targetrects, const qrectf *sourcerects, int fragmentcount,                          const qpixmap &pixmap, pixmapfragmenthints hints = 0); 

qt 5 (5.4.1) has no such function, has 1 (same in qt 4.8) 4 arguments:

void drawpixmapfragments(const pixmapfragment *fragments, int fragmentcount,                          const qpixmap &pixmap, pixmapfragmenthints hints = 0); 

i've searched in wiki.qt.io, here on stackoverflow , several other places, there no answer how port qt 4.8 qt 5.

does know how it?

upd i've taken realization qt 4.8.6 source (qpainter.cpp) , transform take pointer qpainter first parameter:

namespace oldqt {     void drawpixmapfragments(qpainter *painter, const qrectf *targetrects, const qrectf *sourcerects, int fragmentcount,         const qpixmap &pixmap, qpainter::pixmapfragmenthints hints)     {         // q_d(qpainter);           if (/* !d->engine || */ pixmap.isnull())             return;      #ifndef qt_no_debug         if (sourcerects) {             (int = 0; < fragmentcount; ++i) {                 qrectf sourcerect = sourcerects[i];                 if (!(qrectf(pixmap.rect()).contains(sourcerect)))                     qwarning("qpainter::drawpixmapfragments - source rect not contained pixmap's rectangle");             }         }     #endif      // if (d->engine->isextended()) {     //              d->extended->drawpixmapfragments(targetrects, sourcerects, fragmentcount, pixmap, hints);     //          }     //          else {             if (sourcerects) {                 (int = 0; < fragmentcount; ++i)                     painter->drawpixmap(targetrects[i], pixmap, sourcerects[i]);             }             else {                 qrectf sourcerect = pixmap.rect();                 (int = 0; < fragmentcount; ++i)                     painter->drawpixmap(targetrects[i], pixmap, sourcerect);             }     //          }      } } 

but commented out lines. q_d(qpainter) somehow defines d d_func, how can take *painter? or not possible? may there solution?

upd2 example of legacy code:

class buttonselector:public qgraphicsobject // ...  void buttonselector::paint(qpainter *painter, const qstyleoptiongraphicsitem *option, qwidget *widget) {     q_unused(option);     q_unused(widget);     //painter->drawpixmap(m_backgnd.rect(), m_backgnd);     qrectf rectsrc = qrectf(m_backgnd.rect());     qrectf recttrg = boundingrect();     painter->drawpixmapfragments(&recttrg,&rectsrc,1,m_backgnd, qpainter::opaquehint);     // i've change call:     // oldqt::drawpixmapfragments(painter, &recttrg, &rectsrc, 1, m_backgnd, qpainter::opaquehint);     // oldqt::drawpixmapfragments function above      // ... other code unrelated question } 

in principle, works ok. incorrect in code?

solution based on answer @amartel:

void drawpixmapfragments(qpainter *painter, const qrectf *targetrects, const qrectf *sourcerects, int fragmentcount,     const qpixmap &pixmap, qpainter::pixmapfragmenthints hints) {     (int = 0; < 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);     } } 

according http://qt.apidoc.info/5.1.1/qtgui/qpainter-pixmapfragment.html in qt5 code should this:

void buttonselector::paint(qpainter *painter, const qstyleoptiongraphicsitem *option, qwidget *widget) {     q_unused(option);     q_unused(widget);     //painter->drawpixmap(m_backgnd.rect(), m_backgnd);     qrectf rectsrc = qrectf(m_backgnd.rect());     qrectf recttrg = boundingrect();     qpainter::pixmapfragment fragment = qpainter::pixmapfragment::create(recttrg.center(), rectsrc, recttrg.width() / rectsrc.width(), recttrg.height() / rectsrc.height());     painter->drawpixmapfragments(&fragment,1,m_backgnd, qpainter::opaquehint);     // i've change call:     // oldqt::drawpixmapfragments(painter, &recttrg, &rectsrc, 1, m_backgnd, qpainter::opaquehint);     // oldqt::drawpixmapfragments function above      // ... other code unrelated question } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -