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. QToolBar not using QIcon::Mode
Forum Update on Monday, May 27th 2025

QToolBar not using QIcon::Mode

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 290 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.
  • P Offline
    P Offline
    Perdrix
    wrote on 26 Aug 2020, 13:23 last edited by
    #1

    When I populated my ToolBar I used QIcons with four images, one for each QIcon::Mode.

    So the code looks like this:

        QIcon selRect;
        selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp", iconSize, QIcon::Normal);
        selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Disabled.bmp", iconSize, QIcon::Disabled);
        selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Active.bmp", iconSize, QIcon::Active);
        selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Down.bmp", iconSize, QIcon::Selected);
    
        :
        : Similar for the other Icons
        :
        t.setOrientation(Qt::Vertical);
        QAction * rectAction = t.addAction(selRect, "", &editor, &DEditStars::rectButtonChecked);
        QAction * starsAction = t.addAction(selStars, "", &editor, &DEditStars::starsButtonChecked);
        QAction * cometAction = t.addAction(selComet, "", &editor, &DEditStars::cometButtonChecked);
        QAction * saveAction = t.addAction(saveButton, "", &editor, &DEditStars::saveButtonPressed);
    
        QActionGroup selectionGroup(&t);
        rectAction->setCheckable(true);
        starsAction->setCheckable(true);
        cometAction->setCheckable(true);
        selectionGroup.addAction(rectAction);
        selectionGroup.addAction(starsAction);
        selectionGroup.addAction(cometAction);
        selectionGroup.setExclusive(true);
    
    

    But QToolBar appears to use only the QIcon::Normal version for all the buttons, and uses a small offset to indicate an item in the action group has been "checked", rather then using the QIcon::Selected image (I don't mind it keeping the small offset).

    Also it doesn't ever use the QIcon::Active image when the mouse is over the button :(

    Is it possible to persuade the Toolbar to do this, or do I need to build the tool bar the "hard way" by adding sub-classed QToolButton widgets?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 26 Aug 2020, 14:08 last edited by
      #2

      "checked" is QIcon::On from QIcon::State.

      P 1 Reply Last reply 26 Aug 2020, 14:56
      1
      • B Bonnie
        26 Aug 2020, 14:08

        "checked" is QIcon::On from QIcon::State.

        P Offline
        P Offline
        Perdrix
        wrote on 26 Aug 2020, 14:56 last edited by
        #3

        @Bonnie Oh! OK, that's a surprise! I'd very much have expected the checked state to use QIcon::Selected.

        I changed the code to do this:

            QIcon selRect;
            selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.png", iconSize, QIcon::Normal);
            selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Active.bmp", iconSize, QIcon::Active);
            selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Down.bmp", iconSize, QIcon::Normal, QIcon::On);
        

        and that does switch the icon for the checked state - thank you for that.

        I'm guessing from what you didn't say that I can't get it to switch to the active Icon when the mouse is over the button without going down the sub-class route?

        B 1 Reply Last reply 26 Aug 2020, 15:09
        0
        • P Perdrix
          26 Aug 2020, 14:56

          @Bonnie Oh! OK, that's a surprise! I'd very much have expected the checked state to use QIcon::Selected.

          I changed the code to do this:

              QIcon selRect;
              selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.png", iconSize, QIcon::Normal);
              selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Active.bmp", iconSize, QIcon::Active);
              selRect.addFile("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Down.bmp", iconSize, QIcon::Normal, QIcon::On);
          

          and that does switch the icon for the checked state - thank you for that.

          I'm guessing from what you didn't say that I can't get it to switch to the active Icon when the mouse is over the button without going down the sub-class route?

          B Offline
          B Offline
          Bonnie
          wrote on 26 Aug 2020, 15:09 last edited by Bonnie
          #4

          @Perdrix
          No, that's because I don't know about that. :)
          I've set checked pixmaps, but had never set a "hovered" one.
          But I just tested QIcon::Active. Seems to work fine when mouse over.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Perdrix
            wrote on 26 Aug 2020, 16:11 last edited by Perdrix
            #5

            Yes indeed. Once I'd corrected an error in the name of the Active bitmap it works for me too!!

            Thanks a lot!
            David

            1 Reply Last reply
            0

            1/5

            26 Aug 2020, 13:23

            • Login

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