user3568040
user3568040

Reputation: 1

Draw Circle with Dash Dot in my Qt Project

To draw Circle with dash dot what should I include and what code should I use ? I try this codes in my project not work:

QPainter painter(this);
    painter.setBackgroundColor(Qt::cyan);
    painter.setBrush(Qt::yellow);
    painter.drawEllipse(0,0,500,500);

I only see my normal project work not circle or area. Please help and where I write my code ? in main.cpp or myproject.cpp ? Thanks a lot.

Upvotes: 0

Views: 2939

Answers (1)

Nejat
Nejat

Reputation: 32655

You should write your code for example in the paint event of a QGraphicsItem or in the paintEvent of a QWidget. You can also use Qt::DashDotLine for the pen:

void myItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setRenderHint(QPainter::Antialiasing,true);
    painter->setWindow( -500,-500,1000,1000);
    painter->setViewport( -500,-500,1000,1000);

    painter->setPen(QPen(Qt::black, 20, Qt::DashDotLine));

    painter->setBrush(Qt::yellow);
    painter->drawEllipse(-450, -450, 900, 900);
}

Upvotes: 1

Related Questions