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);
    px->fill(state);
    painter->drawText(px->rect(),Qt::AlignCenter,lfnr);
    QIcon *icon = new QIcon;
    icon->setPixmap(px);
    
    

    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


  • Qt Champions 2016

    @the_ said:
    Hi Maybe If you make background transparent and draw a round icon.
    painter.fill(Qt::Transparent);
    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

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



  • @raven-worx said:

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

    Thanks, that draws a nice colored circle :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.