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. How write inside a pie chart
Qt 6.11 is out! See what's new in the release blog

How write inside a pie chart

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.2k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    I tried to draw a pie chart but I want write inside..How Can I?
    this is my code of the class

    #include "pie.h"
    #include <QPainter>

    Pie::Pie(QWidget *parent) : QWidget(parent)
    {

    }

    void Pie::paintEvent(QPaintEvent *)
    {
    QPainter painter(this);
    QRectF size = QRectF(10,10,this->width()-10, this->width()-10);
    painter.setBrush(Qt::gray);
    painter.drawPie(size, a,b);
    QPen pen(Qt::red);
    //painter.setPen(pen);

    // painter.setRenderHints(QPainter::Antialiasing,true);
    painter.pen();
    painter.setBrush(Qt::gray);
    painter.drawPie(size,c,d);
    painter.drawText(10,10,"10");

    }

    jsulmJ 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is an example already present in the examples directory. Can you look at it.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      ? 1 Reply Last reply
      0
      • dheerendraD dheerendra

        There is an example already present in the examples directory. Can you look at it.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @dheerendra yes but in the example they use qCharts

        1 Reply Last reply
        0
        • ? A Former User

          I tried to draw a pie chart but I want write inside..How Can I?
          this is my code of the class

          #include "pie.h"
          #include <QPainter>

          Pie::Pie(QWidget *parent) : QWidget(parent)
          {

          }

          void Pie::paintEvent(QPaintEvent *)
          {
          QPainter painter(this);
          QRectF size = QRectF(10,10,this->width()-10, this->width()-10);
          painter.setBrush(Qt::gray);
          painter.drawPie(size, a,b);
          QPen pen(Qt::red);
          //painter.setPen(pen);

          // painter.setRenderHints(QPainter::Antialiasing,true);
          painter.pen();
          painter.setBrush(Qt::gray);
          painter.drawPie(size,c,d);
          painter.drawText(10,10,"10");

          }

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @vale88 said in How write inside a pie chart:

          but I want write inside

          So, your code is not doing what you want? Does it write text outside the pie?
          You really should explain better what the problem is.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          ? 1 Reply Last reply
          0
          • jsulmJ jsulm

            @vale88 said in How write inside a pie chart:

            but I want write inside

            So, your code is not doing what you want? Does it write text outside the pie?
            You really should explain better what the problem is.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @jsulm I want a text outside the pie

            jsulmJ 1 Reply Last reply
            0
            • ? A Former User

              @jsulm I want a text outside the pie

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @vale88 then draw it outside the pie. I'm not sure what the problem is.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              ? 1 Reply Last reply
              0
              • jsulmJ jsulm

                @vale88 then draw it outside the pie. I'm not sure what the problem is.

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                @jsulm yes but I don't know how I can do it

                jsulmJ 1 Reply Last reply
                0
                • ? A Former User

                  @jsulm yes but I don't know how I can do it

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @vale88 I guess your problem is that you do not know at which position to draw your text, so it does not cover the pie, is that correct? You need to calculate that. You know where your pie is and how big it is. You would somehow need to know how much space your text is going to occupy (bounding box). Then you can calculate the position for the text.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  • Login

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