Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating round QIcon from string
Forum Updated to NodeBB v4.3 + New Features

Creating round QIcon from string

Scheduled Pinned Locked Moved Solved General and Desktop
qicon
5 Posts 3 Posters 4.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • the_T Offline
    the_T Offline
    the_
    wrote on last edited by
    #1

    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

    -- No support in PM --

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      the_T 1 Reply Last reply
      3
      • mrjjM mrjj

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

        the_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #3

        @mrjj

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

        -- No support in PM --

        raven-worxR 1 Reply Last reply
        0
        • the_T the_

          @mrjj

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

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          the_T 1 Reply Last reply
          1
          • raven-worxR raven-worx

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

            the_T Offline
            the_T Offline
            the_
            wrote on last edited by
            #5

            @raven-worx said:

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

            Thanks, that draws a nice colored circle :)

            -- No support in PM --

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved