Nominate our 2022 Qt Champions!

Creating round QIcon from string

  • Hi all,

    just another question from me :)

    I have a QListWidget that contains several items. Each item should get an icon that displays the a state (color code) and text (numbering). What i already have is the QIcon with text and color code.

     QString lfnr;
    //<some more code here>
    QPixmap *px = new QPixmap(40,40);
    QPainter *painter(px);
    QIcon *icon = new QIcon;

    My question is now, what is the easiest way to create a round icon (which in my opinion looks much more fancy than a square :) )

    Thanks for help

  • Lifetime Qt Champion

    @the_ said:
    Hi Maybe If you make background transparent and draw a round icon.
    painter.drawEllipse(10, 10, 50, 50);

  • @mrjj

    Yes that draws a circle into the pixmap, but how to fill that circle with some color? painter as no fill method.

  • Moderators

    use QPainter::setBrush() before the drawEllipse() call

  • @raven-worx said:

    use QPainter::setBrush() before the drawEllipse() call

    Thanks, that draws a nice colored circle :)

Log in to reply