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. Get state of a QIcon?
Forum Updated to NodeBB v4.3 + New Features

Get state of a QIcon?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 452 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.
  • C Offline
    C Offline
    Calicoder
    wrote on last edited by
    #1

    Howdy fellow QT'ers folks, hope everyone is doing well. Been playing with creating QIcons for the past week, checked the official docs and don't see how one can fetch the state the icon is currently in?

    app.h

    private:
        QIcon goSign;
    

    app.cpp

    goSign.addPixmap(QPixmap(":/img/go.png"), QIcon::Normal, QIcon::On);
    goSign.addPixmap(QPixmap(":/img/stop.png"), QIcon::Normal, QIcon::Off);
    

    I can set the QIcon by using the proper QIcon::State value but can this be fetched afterwards? I figured I could grab the int value of the enum QIcon::State but the QIcon goSign doesn't have a getState function.

    Any ideas on how to handle this would be greatly appreciated. Thanks

    JonBJ 1 Reply Last reply
    0
    • C Calicoder

      Howdy fellow QT'ers folks, hope everyone is doing well. Been playing with creating QIcons for the past week, checked the official docs and don't see how one can fetch the state the icon is currently in?

      app.h

      private:
          QIcon goSign;
      

      app.cpp

      goSign.addPixmap(QPixmap(":/img/go.png"), QIcon::Normal, QIcon::On);
      goSign.addPixmap(QPixmap(":/img/stop.png"), QIcon::Normal, QIcon::Off);
      

      I can set the QIcon by using the proper QIcon::State value but can this be fetched afterwards? I figured I could grab the int value of the enum QIcon::State but the QIcon goSign doesn't have a getState function.

      Any ideas on how to handle this would be greatly appreciated. Thanks

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Calicoder
      I agree that from what I can see in the docs there are no getters for the QIcon::Mode or QIcon::State: they seem to be passed into constructor/methods only. So if you need that information suggest subclass from QIcon and save mode/state into a member variable. Or in your case I think you just need to create a wrapper class for the QPixmap you create saving the icon state/mode with it.

      C 1 Reply Last reply
      1
      • JonBJ JonB

        @Calicoder
        I agree that from what I can see in the docs there are no getters for the QIcon::Mode or QIcon::State: they seem to be passed into constructor/methods only. So if you need that information suggest subclass from QIcon and save mode/state into a member variable. Or in your case I think you just need to create a wrapper class for the QPixmap you create saving the icon state/mode with it.

        C Offline
        C Offline
        Calicoder
        wrote on last edited by
        #3

        @JonB Appreciate the 2nd set of eyes to look that over. That's what I'll do before setting the icon. Thanks so much!

        JonBJ 1 Reply Last reply
        0
        • C Calicoder

          @JonB Appreciate the 2nd set of eyes to look that over. That's what I'll do before setting the icon. Thanks so much!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Calicoder
          Further, it's not really a QIcon which has the state or mode. It is that it can generate icons for them from the pixmaps it has available.

          A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action.

          You went

          goSign.addPixmap(QPixmap(":/img/go.png"), QIcon::Normal, QIcon::On);
          

          So it's the QPixmap you are adding which has the Normal/On attributes.

          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