Difficulty central pixmap inside Ellipse



  • drawPixmap-Drawing rectangular portion source of the given image into target rectangle
    painter.drawPixmap(rectangle,pixmap,source);
    Having difficulty central pixmap inside Ellipse

    '''
    #include "circlepict.h"
    #include <QtWidgets>

    CirclePict::CirclePict(QWidget *parent)
    : QWidget(parent)
    {
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(1000);

    setWindowTitle(tr("MyWidget"));
    resize(200, 200);
    

    }

    void CirclePict::paintEvent(QPaintEvent *)
    {
    QPainter painter(this);

    QPixmap pm(100,100);
    pm.fill();
    painter.setRenderHint(QPainter::Antialiasing);
    
    QPen pen1(Qt::red,6);
    painter.setPen(pen1);
    QRectF rectangle(20.0,20.0,160.0,180.0);
    QRectF CircleRect(10,10,180,180);
    QRectF source(0.0,0.0,70.0,70.0);
    
    QPixmap pixmap(":house.png");
    painter.drawPixmap(rectangle,pixmap,source);
    painter.drawEllipse(CircleRect);
    

    }


  • Lifetime Qt Champion

    Hi,

    Can you explain what you are trying to achieve and what is currently happening ?



  • Want to centre a pixmap in a circle.
    The pixmap is not central entirely inside the circle. A bit of the pixmap is outside this circle.

    The class is circlepict.cpp in github
    https://github.com/houmingc/CircularProgressBar/tree/master/analogclock


  • Lifetime Qt Champion

    You need to do some maths to either calculate the size of a rectangle for a given circle or the circle for a given rectangle.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.