Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Difficulty central pixmap inside Ellipse

    General and Desktop
    2
    4
    699
    Loading More Posts
    • 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
      alvinNew last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • A
          alvinNew last edited by alvinNew

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • First post
              Last post