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. Drawing circles using QPainter
Qt 6.11 is out! See what's new in the release blog

Drawing circles using QPainter

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 10.7k Views 3 Watching
  • 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.
  • N Offline
    N Offline
    n-2204
    wrote on last edited by
    #1

    Hi,
    1->I need to draw circles based on user value in a table(Qtableview).
    2->draw/connect two circle using line (CD)
    3->shows direction in circle like arc kind (--->)
    4->i need to display this circle in my tab2 (Qtabwidget)
    How to do this ?

    like simply i can do like this:

    {
    QPainter myellip(this);
    QPen epen;
    int x = 10;
    epen.setWidth(3);
    epen.setColor(Qt::yellow);
    epen.setBrush(Qt::SolidPattern);
    // myellip.setBrush(Qt::SolidPattern);
    myellip.setPen(epen);
    myellip.drawEllipse(QRect(150, 300, 100, 100));
    }
    

    How can i do these all ? How to approach ?

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

      Hi,

      Do you mean as an overlay ?

      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
      2
      • N Offline
        N Offline
        n-2204
        wrote on last edited by n-2204
        #3

        09cf0862-54b2-457d-b0e3-4af3757c3add-image.png
        like this I need to do
        How to do ?
        If anyone has any example related to this plz share

        1 Reply Last reply
        0
        • N Offline
          N Offline
          n-2204
          wrote on last edited by
          #4
          void table_model::paintEvent(QPaintEvent* event)  
          {
          QPainter myellip(this);
          QPen epen;
          int x = 10;
          epen.setWidth(3);
          epen.setColor(Qt::yellow);
          epen.setBrush(Qt::SolidPattern);
           // myellip.setBrush(Qt::SolidPattern);
          myellip.setPen(epen);
          myellip.drawEllipse(QRect(150, 300, 100, 100));
          }
          

          how can i display this circle in my tab2 (Qtabwidget)

          BondrusiekB 1 Reply Last reply
          0
          • N n-2204
            void table_model::paintEvent(QPaintEvent* event)  
            {
            QPainter myellip(this);
            QPen epen;
            int x = 10;
            epen.setWidth(3);
            epen.setColor(Qt::yellow);
            epen.setBrush(Qt::SolidPattern);
             // myellip.setBrush(Qt::SolidPattern);
            myellip.setPen(epen);
            myellip.drawEllipse(QRect(150, 300, 100, 100));
            }
            

            how can i display this circle in my tab2 (Qtabwidget)

            BondrusiekB Offline
            BondrusiekB Offline
            Bondrusiek
            wrote on last edited by
            #5

            @n-2204
            Hi,
            maybe try use function paintEvent() in tab2 ie:

            void tab2::paintEvent(QPaintEvent* event)  
            {
            QPainter myellip(this);
            QPen epen;
            int x = 10;
            epen.setWidth(3);
            epen.setColor(Qt::yellow);
            epen.setBrush(Qt::SolidPattern);
             // myellip.setBrush(Qt::SolidPattern);
            myellip.setPen(epen);
            myellip.drawEllipse(QRect(150, 300, 100, 100));
            }
            
            1 Reply Last reply
            1
            • N Offline
              N Offline
              n-2204
              wrote on last edited by
              #6

              Oh,,actually i haven't created class for tab2 widget
              QPainter myellip(this);
              can't i do like this-> QPainter myellip(ui.tab2);

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

                No, you cannot paint on another widget.

                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
                2
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  well you can paint on a pixmap and show in a QLabel

                   QPixmap pix(200, 200);
                    pix.fill(Qt::blue);
                    QPainter painter (&pix);
                    painter.setRenderHint(QPainter::Antialiasing, true);
                    ..... draw ...
                    ui->label->setPixmap(pix);
                  
                  N 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    Hi
                    well you can paint on a pixmap and show in a QLabel

                     QPixmap pix(200, 200);
                      pix.fill(Qt::blue);
                      QPainter painter (&pix);
                      painter.setRenderHint(QPainter::Antialiasing, true);
                      ..... draw ...
                      ui->label->setPixmap(pix);
                    
                    N Offline
                    N Offline
                    n-2204
                    wrote on last edited by
                    #9

                    @mrjj
                    ok Thankyou..
                    using Qpixmap & Qpainter is a good approach to draw the circles as i shared image above and i need to draw arc, lines & input for circle is from Qtableview

                    mrjjM 1 Reply Last reply
                    0
                    • N n-2204

                      @mrjj
                      ok Thankyou..
                      using Qpixmap & Qpainter is a good approach to draw the circles as i shared image above and i need to draw arc, lines & input for circle is from Qtableview

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @n-2204

                      Hi
                      If you data is from a View, its actually from its model.

                      but was it a question or ?

                      QPainter has all the functions you need to do it.

                      except maybe for the small arrow inside the circle

                      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