Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Drawing circles using QPainter



  • 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 ?


  • Lifetime Qt Champion

    Hi,

    Do you mean as an overlay ?



  • 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



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



  • @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));
    }
    


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


  • Lifetime Qt Champion

    No, you cannot paint on another widget.


  • Lifetime Qt Champion

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


  • @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


  • Lifetime Qt Champion

    @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


Log in to reply