Reply to topic

GeoPainter draw rotated Pixmaps display black rectangles

Registered Member
Hello everyone,

new to Marble and even Qt I try to extend GeoPainter to draw pixmaps rotated around and placed at an anchor point.

The function works flawless with a pure QtWidget, but added to GeoPainter just 2 or 3 pixmaps are drawn for the rest I get black rectangles. To test I arranged 10 objects in a circle, I can pan the map around to move objects out of the viewport but never get more than 3 painted correctly.

Here is the code:
Code: Select all
void GeoPainter::drawPixmap ( const GeoDataCoordinates & centerPosition,
                              const QPixmap & pixmap,
                              QPointF anchorRelative,
                              qreal angle,
                              qreal scalePixel,
                              qreal scaleMeter/*=0.0*/ )
    int pointRepeatNum;
    qreal x, y;
    bool globeHidesPoint;

    bool visible = d->m_viewport->screenCoordinates( centerPosition, x, y, globeHidesPoint );

    if ( visible ) {
       QPoint screenPos(x, y);

       if( 0.0 < scaleMeter ) {
          qreal scaleFromMeter(0);
          //TODO, calculate meter to pixel
          if( scalePixel < scaleFromMeter ) scalePixel = scaleFromMeter;
       qreal ratio = scalePixel / pixmap.height();
       QPointF scaledSize(pixmap.width() * ratio, scalePixel);
       QPointF pntCenter(scaledSize / 2);
       QPointF pntAnchor(anchorRelative.rx() * scaledSize.x(), anchorRelative.ry() * scaledSize.y());

       qreal dist = QLineF(pntAnchor, pntCenter).length();
       qreal a = qAtan2(pntAnchor.y() - pntCenter.y(), pntAnchor.x() - pntCenter.x());

       QPointF rotAnchor(qCos(angle + a) * dist, qSin(angle + a) * dist);
       rotAnchor += pntCenter;

        QPixmap rotImage = pixmap.transformed(QTransform()
                                  .scale(ratio, ratio)
                                  .translate(-screenPos.x(), -screenPos.y())
                                  .translate(screenPos.x(), screenPos.y())

       QPointF rotCenter = QPointF(rotImage.width() / 2, rotImage.height() / 2);
       QPointF offset(rotCenter - pntCenter);

       QPointF origin(screenPos - (rotAnchor + offset));
        QPainter::drawPixmap(origin, rotImage);

When I comment out .rotateRadians(angle) all objects get painted.

Anyone knows what the problem is and how to fix it?

Best regards
Registered Member
Found the issue, coding above is correct. The problem was some time ago I derived MarbleWidget from QOpenGLWidget. Everything seemed to work. Now after I switched back to QWidget all rotated pixmaps get drawn. I need to check the OpenGL initialization.

Thanks for your time!


Reply to topic


Who is online

Registered users: availakis, Baidu [Spider], Bing [Bot], Exabot [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]