Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Difficulty central pixmap inside Ellipse
QtWS25 Last Chance

Difficulty central pixmap inside Ellipse

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 872 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alvinNew
    wrote on last edited by
    #1

    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);
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alvinNew
        wrote on last edited by alvinNew
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved