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

Draw ellipse with border. [SOLVED]



  • Hello guys, I am using this code to draw a circle.

    @ QPainterPath circle_path;
    circle_path.addEllipse(rect);
    painter->drawPath(circle_path);@

    Is there anyway to fillup the circle with a color and draw its border with another color or I need two differents circle?
    thanks



  • Hi, have you tried:
    @painter->setPen(QColor(0x55, 0x55, 0xFF));
    painter->setBrush(QColor(0xFF, 0x55, 0x55));@



  • no I havent. The only I could think out was draw an ellipse inside another ellipse. I will try this. thanks.

    EDIT: does not work. It does not draw the ellipse



  • It sets the pen and brush color to be used when painting, you still need to draw the ellipse:
    @QPainterPath circle_path;
    circle_path.addEllipse(rect);
    painter->setPen(QColor(0x55, 0x55, 0xFF));
    painter->setBrush(QColor(0xFF, 0x55, 0x55));
    painter->drawPath(circle_path);@



  • of course I painted the ellipse.



  • @void mainWindow::paintEvent(QPaintEvent *)
    {
    QPainterPath circle_path;
    circle_path.addEllipse(QRect(10,10,100,200));
    QPainter painter(this);
    painter.setPen(QPen(QColor(0x55, 0x55, 0xFF),20));
    painter.setBrush(QColor(0xFF, 0x55, 0x55));
    painter.drawPath(circle_path);

    }@

    result:
    !http://zalil.ru/33883490/379ff813.508767c0/ELLIPSE.png(RESULT)!

    Is this what you'd like to achive?



  • [quote author="terenty" date="1351009704"]
    @void mainWindow::paintEvent(QPaintEvent *)
    {
    QPainterPath circle_path;
    circle_path.addEllipse(QRect(10,10,100,200));
    QPainter painter(this);
    painter.setPen(QPen(QColor(0x55, 0x55, 0xFF),20));
    painter.setBrush(QColor(0xFF, 0x55, 0x55));
    painter.drawPath(circle_path);

    }@

    result:
    !http://zalil.ru/33883490/379ff813.508767c0/ELLIPSE.png(RESULT)!

    Is this what you'd like to achive?[/quote]

    works like a charm. Sorry for the misunderstanding.


Log in to reply