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. QIcon not showing anything
Qt 6.11 is out! See what's new in the release blog

QIcon not showing anything

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.4k Views
  • 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.
  • Q Offline
    Q Offline
    Q74r3wq-
    wrote on last edited by
    #1

    Hi experts, actually two questions:

    1 - How do I assign a png file to an icon in QT Creator?
    When I click on the "icon" part, it asks for a "theme". his is confusing as I expect it to show a dialog and I can simply load an image file.

    2 - How do I load it in program?
    Here is the code:

    QIcon ButtonIcon("loadbutton.png");
    ui.loadButton->setIcon(ButtonIcon);
    ui.loadButton->setIconSize(pixmap.rect().size());
    

    Let me say the filename is perfectly fine (as I put the png in the same directory and it's also the method I use to load all other png files), and ButtonIcon is not NULL. However the icon shows nothing and I don't know why.

    Thanks in advance!

    jsulmJ 1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      @Q74r3wq said in QIcon not showing anything:

      When I click on the "icon" part, it asks for a "theme".

      In the Designer properties panel click the small down arrow, then Choose File... (or Choose Resource... and embed the icon)
      Screenshot_20210701_143037.png

      Themes use the Freedesktop Icon Theme Specification and are another way to handle sets of icons.

      2 - How do I load it in program?

      Like you are doing (assuming the executable's current working directory is where "loadbutton.png" lives).
      What is the unrelated pixmap.rect().size()?

      1 Reply Last reply
      0
      • Q Q74r3wq-

        Hi experts, actually two questions:

        1 - How do I assign a png file to an icon in QT Creator?
        When I click on the "icon" part, it asks for a "theme". his is confusing as I expect it to show a dialog and I can simply load an image file.

        2 - How do I load it in program?
        Here is the code:

        QIcon ButtonIcon("loadbutton.png");
        ui.loadButton->setIcon(ButtonIcon);
        ui.loadButton->setIconSize(pixmap.rect().size());
        

        Let me say the filename is perfectly fine (as I put the png in the same directory and it's also the method I use to load all other png files), and ButtonIcon is not NULL. However the icon shows nothing and I don't know why.

        Thanks in advance!

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Q74r3wq said in QIcon not showing anything:

        QIcon ButtonIcon("loadbutton.png");

        You are using a relative path for the icon. That means your app will look in current working directory for it. You should use resources for such files instead. See https://doc.qt.io/qt-5/resources.html

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

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