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. RichText: how to insert "icon from theme" ?

RichText: how to insert "icon from theme" ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    dextermagnific
    wrote on last edited by
    #1

    Hi all,
    I'd like to build a QLabel which displays rich text and I'd like to insert an icon from the theme spec. I know I can insert images from a resource file but how about icons from themes ?
    Thanks

    1 Reply Last reply
    0
    • KH-219DesignK Offline
      KH-219DesignK Offline
      KH-219Design
      wrote on last edited by
      #2

      You mention QLabel, which I recognize is not QML and yet I am about to share something that worked for me in QML.

      So please take my answer as a "hint." All my Qt work is in QML (not QWidgets), so my experience does not overlap directly with your use case.

      In Qt5, I was able to utilize an icon that is compiled into one of the binary libraries that is part of the Qt framework.

      My line of QML looks like:

      source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/double-arrow.png"
      

      And the "double-arrow.png" is compiled into:

      /usr/lib/x86_64-linux-gnu/qt5/qml/QtQuick/Controls.2/libqtquickcontrols2plugin.so
      

      I have forgotten how I discovered that "double-arrow" was available to me in this way. I probably encountered it via some sample code or official Qt example app.

      If I were to go hunting and digging for options available to me nowadays (in Qt6), I might start (on Linux) with something like this:

      strings ./lib/libQt6Gui.so | grep -w png
      

      ... which shows:

      :/qt-project.org/styles/commonstyle/images/file-16.png
      

      which tells me that I can probably use "qrc:/qt-project.org/styles/commonstyle/images/file-16.png" just fine.

      Similar tactics would probably work for all the PNG files seen here: https://github.com/qt/qtbase/tree/dev/src/widgets/styles/images

      www.219design.com
      Software | Electrical | Mechanical | Product Design

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dextermagnific
        wrote on last edited by
        #3

        I guess this would work in a QLabel too because you use an image (not an icon) and its source is inside a file (real or resource).
        What I'm trying to achieve is to put an icon from the "system" theme. That's another story I think because it needs resolution.
        In fact I would like this function
        https://doc.qt.io/qt-6/qicon.html#fromTheme
        to be set as a source.

        1 Reply Last reply
        0
        • KH-219DesignK Offline
          KH-219DesignK Offline
          KH-219Design
          wrote on last edited by
          #4

          Hopefully someone with more experience than I with "icon themes" can come and comment. Please, come one; come all 🙏

          @dextermagnific Ok got it. Well in your case, I went and skimmed this file: https://github.com/qt/qtbase/blob/dev/src/gui/image/qiconloader.cpp

          In skimming the code, it appeared to me that the only platform-specific implementation is QIconCacheGtkReader.

          Thankfully (for my sanity), it appears that the docs confirm this:

          • https://doc.qt.io/qt-6/qicon.html#themeName (quote: "Platform icon themes are only implemented on Freedesktop based systems at the moment")
          • https://doc.qt.io/qt-6/qicon.html#fallbackThemeName (quote: "Platform fallback icon themes are only implemented on Freedesktop based systems at the moment")

          So that makes me wonder if you only need your planned icon-theme approach to work on Linux? Have you tried QIcon::fromTheme on Windows or Mac and were you happy with the results?

          (Keep in mind that I am still speaking as someone who has not used the "icon theme" feature of QWidgets even once. Please double-check my comments with added research because I don't want to lead anyone astray!)

          If you only need it to work on Linux, then you can probably just look at QIconCacheGtkReader and learn how the icon selection is done for Freedesktop. (note to readers: I acknowledge my sloppy language conflating Linux and Freedesktop.)

          www.219design.com
          Software | Electrical | Mechanical | Product Design

          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