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. Qt 4.8.6 QToolButton doesn't accept custom disabled icon
Forum Updated to NodeBB v4.3 + New Features

Qt 4.8.6 QToolButton doesn't accept custom disabled icon

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.7k 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.
  • H Offline
    H Offline
    Hubee
    wrote on 12 Dec 2015, 17:54 last edited by
    #1

    Hi,
    I want to use own, custom svg icons for different tool button states:
    QIcon toolIcon;
    toolIcon.addFile(":/datatableplugin/report-inactive.svg", QSize(), QIcon::Disabled, QIcon::Off);
    toolIcon.addFile(":/datatableplugin/report-inactive.svg", QSize(), QIcon::Disabled, QIcon::On);
    toolIcon.addFile(":/datatableplugin/report-normal.svg", QSize(), QIcon::Normal, QIcon::Off);
    toolIcon.addFile(":/datatableplugin/report-active.svg", QSize(), QIcon::Normal, QIcon::On);
    toolIcon.addFile(":/datatableplugin/report-active.svg", QSize(), QIcon::Active, QIcon::On);
    toolIcon.addFile(":/datatableplugin/report-hover.svg", QSize(), QIcon::Active, QIcon::Off);
    QToolButton* button = new QToolButton();
    button->setIcon(toolIcon);

    All works, except when the tool button is in disabled state, the icon from "report-inactive.svg" is modified (lightened up) instead of being used directly. Looks like icon engine generates pixmap in disabled state from the file provided. But I don't want that behavior. I want to see the icon in disabled state as it has been designed in the file, without any modification. What is wrong? Is it a bug? Other states respect their files and icons are not additionally modified.
    If I use .png file for disabled state it works! But I have to use .svg because the icon up-scales automatically to the button size and always looks good.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Dec 2015, 22:08 last edited by
      #2

      Hi and welcome to devnet,

      Can you test that against Qt 4.8.7 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hubee
        wrote on 13 Dec 2015, 12:15 last edited by Hubee
        #3

        No, I didn't try 4.8.7. I don't think it would work, because there are no changes for QIcon, QSvgIconEngine and others which may be related.
        I think I've solved the problem. If one is interested may look and compare QPixmapIconEngine::pixmap() and QSvgIconEngine::pixmap(). The svg engine always tries to generate a pixmap for the state from the current style, even if there is a file provided. And for ::Disabled state it modifies icon colors. Pixmap engine doesn't try to generate if there is already a pixmap provided for the state with the correct size.
        I don't think it is the right approach. If there is a file provided for a state, the engine should always use it without modification.
        But anyway, there is a workaround. One has to define a custom style derived from QProxyStyle and override generatedIconPixmap() virtual function, so it would return unmodified pixmap for a given mode. The custom style should be set as the application style.
        I tried it and it worked.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Dec 2015, 23:06 last edited by
          #4

          Good catch !

          Thanks for sharing your findings :)

          It's too late for the Qt 4 series but if you want, you could submit a patch for Qt 5 to fix that. If not, please consider opening a bug on the bug report system providing all the informations you have at hand so it can be fixed in a future version.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          12 Dec 2015, 17:54

          • Login

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