Important: Please read the Qt Code of Conduct -

QPainter trick .

  • Hi Qt Community ,

    I tried countless times to create a certain shape but i failed :

    I want to draw a "donut"-like shape whose center is transparent , so i tried something like this , but it was in vain :


    Any ideas ?

  • @Walux said:

    Any ideas ?

        QPainterPath path;
        path.addEllipse(0, 0, 400, 400);
        painter->setBrush( QBrush(QColor("black")) );

  • @Wieland

    Works like a charm !
    I wonder why this worked !

  • @Walux said:

    I wonder why this worked

    See QPainterPath Class, especially note:

    Finally we draw the entire path. The path is filled using the default fill rule, Qt::OddEvenFill.


    Specifies that the region is filled using the odd even fill rule. With this rule, we determine whether a point is inside the shape by using the following method. Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape. This mode is the default.

  • @Wieland

    Very informative :)
    U have my precious thanks ;)

  • @Walux :-)

Log in to reply