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. [Solved] Standard way to use Icons in Qt application?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Standard way to use Icons in Qt application?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 7.2k Views 1 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.
  • C Offline
    C Offline
    CAD_coding
    wrote on 9 Jul 2013, 15:02 last edited by
    #1

    Hi,

    I am having some problem trying to use an icon for my application.
    Since this is my first time at application development I am sorry for asking a simple question.

    I am creating the image in Inkscape. But dont know what size I should create in?
    Previously I tried using a fairly large image (200x200px JPEG format) as a resource file then use it as an icon.
    But it was giving a very bad quality.
    So my question is:

    1. What size image should I create in Inkscape?
    2. What file format should I use?
    3. Should I directly use the image or create a QIcon then use?
    4. What is the best way to have good quality icon if above mentioned approach is wrong?

    Any other suggestions are also welcome!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 9 Jul 2013, 16:00 last edited by
      #2

      The most common icon size is 32x32 pixels. Automatic resizing - just as you have noticed yourself - usually results in the picture looking ugly, so it's probably best to render additional sizes manually (16x16, 64x64, maybe more if you feel like it).

      As for the extension - I would go for PNG.

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CAD_coding
        wrote on 10 Jul 2013, 15:25 last edited by
        #3

        Hi sierdzio,

        I used qApp->setWindowIcon(QIcon("<abs path to PNG file>"));
        This made the icon for main window title as well as task bar icon using my image file.

        Now, 32x32 is fine for window title bar.
        But dont you think it is less for taskbar icon?
        Is it possible to specify different image for task bar icon?

        Also, you mentioned to create "additional sizes manually (16×16, 64×64, maybe more if you feel like it).", why is it required to create these many images?

        Thanks!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 11 Jul 2013, 05:57 last edited by
          #4

          For various reasons:

          • if the icon will be used somewhere inside the application, and it would be better to have it bigger (for example, Qt logo can be found in "About Qt" dialog)
          • for shortcut icons (.lnk on Windows, various other on Linux and Mac)

          You can of course keep the original, big file somewhere and create scaled down copies when they are needed. SVG and PNG are probably best options here.

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CAD_coding
            wrote on 11 Jul 2013, 15:03 last edited by
            #5

            Hi sierdzio,

            Yes thats what my big problem is!
            How to specify different images for different purposes?

            Now,
            qApp->setWindowIcon(QIcon(”<abs path to PNG file>”));
            uses the specified image file for Title bar icon, fair enough.

            But it also uses it for Task bar icon, not fair enough.
            How to specify different image file path for Task bar icon?

            Also similarly how to specify another image file for shortcut icons, which you mentioned?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 11 Jul 2013, 16:06 last edited by
              #6

              I don't know about changing the taskbar icon, I've never experimented with it, to be honest. What you could try, is to set the taskbar icon with qApp as you are doing now, but then set the main window icon separately in your code (QWidget::setWindowIcon()).

              As for application shortcut, the case here is rather complicated and depends heavily on the Operating System. On Windows, you need to specify the icon in "a rc file":http://stackoverflow.com/questions/1460361/qt-creator-how-to-set-application-icon, on a Mac, you need to use info.plist file to add path to the icon file. On Linux, it gets even more challenging, because every desktop environment (KDE, Gnome, Xfce, etc.) has it's own rules. Sadly, Qt will not help you here much, you need to handle it by yourself.

              (Z(:^

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CAD_coding
                wrote on 11 Jul 2013, 16:42 last edited by
                #7

                Ohh....
                that did not come to my mind at all!
                Will try that & get back to you.
                Thanks for the additional info as well.

                Honestly speaking you have saved me from a lot of headache, as I was trying to figure out this for a pretty long time.
                Thank You...

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  belab
                  wrote on 11 Jul 2013, 17:51 last edited by
                  #8

                  [quote author="sierdzio" date="1373558808"]... As for application shortcut, the case here is rather complicated and depends heavily on the Operating System. On Windows, you need to specify the icon in "a rc file":http://stackoverflow.com/questions/1460361/qt-creator-how-to-set-application-icon, on a Mac, you need to use info.plist file to add path to the icon file. On Linux, it gets even more challenging, because every desktop environment (KDE, Gnome, Xfce, etc.) has it's own rules. Sadly, Qt will not help you here much, you need to handle it by yourself.[/quote]

                  Thers is another way described "here...":http://doc-snapshot.qt-project.org/qt5-stable/qtdoc/appicon.html

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sierdzio
                    Moderators
                    wrote on 11 Jul 2013, 18:02 last edited by
                    #9

                    It's basically the same I wrote, but the description is more elaborate and precise. Thank you for the link, I was not aware this was in the docs.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      CAD_coding
                      wrote on 12 Jul 2013, 06:23 last edited by
                      #10

                      Strange thing just happened!

                      As I told previously the setWindowIcon() was applying the specified image for title bar as well as task bar icon, looks like that is not true.
                      I was running my application from Qt Creator (ctrl + r) & hence I was getting this result. But if I compile my exe & then run it manually through explorer, then only title bar icon gets generated. But task bar icon is not generated!
                      Is this a bug with Qt Creator or does it works to spec?

                      I guess to set the task bar icon I have to use the method for windows icon.
                      @belab thanks for that link.

                      1 Reply Last reply
                      0

                      1/10

                      9 Jul 2013, 15:02

                      • Login

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