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.
  • T Offline
    T Offline
    the_
    wrote on 1 Feb 2016, 09:33 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 1 Feb 2016, 09:38 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);

      T 1 Reply Last reply 1 Feb 2016, 10:32
      3
      • M mrjj
        1 Feb 2016, 09:38

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

        T Offline
        T Offline
        the_
        wrote on 1 Feb 2016, 10:32 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 --

        R 1 Reply Last reply 1 Feb 2016, 10:34
        0
        • T the_
          1 Feb 2016, 10:32

          @mrjj

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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 1 Feb 2016, 10:34 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

          T 1 Reply Last reply 1 Feb 2016, 10:50
          1
          • R raven-worx
            1 Feb 2016, 10:34

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

            T Offline
            T Offline
            the_
            wrote on 1 Feb 2016, 10:50 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

            3/5

            1 Feb 2016, 10:32

            • Login

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