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. Defining Path
QtWS25 Last Chance

Defining Path

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 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.
  • R Offline
    R Offline
    Revu
    wrote on last edited by
    #1

    I need to update different images(stored in different path) on the same PushButton at different events.How can I do this without using pustbutton->setIcon(:/pathoftheimage/image1) for the second time as pustbutton->setIcon(:/pathoftheimage2/image2) and so on.
    Please help.

    Thanks,
    Revu

    Every fall is to raise higher than Before.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      It depens what event means to you.

      You can add different pixmaps to QIcon using QIcon::addPixmap() or QIcon::addFile() for different modes (normal, disabled, active, selected) and states (on, off) which are then automatically displayed when the QPushButton enters a specific state and mode.

      If an event is something specific to your application there is no way around using QPushButton::setIcon(). If you don't want to have different pathes all over you code you could for example

      • use a central icon pool
        @
        class YourClass
        {
        ...

      public:
      enum Icon
      {
      StateAIcon,
      StateBIcon
      };

      QIcon icon(YourClass::Icon icon)
      {
          return ...;
      }
      
      ...
      
      void stateAEvent()
      {
          pushButton->setIcon(icon(YourClass::StateAIcon));
      }
      

      };
      @

      • use resource aliases
        @
        class YourClass
        {
        ...

      public:
      void stateAEvent()
      {
      pushButton->setIcon(QIcon(":/icons/stateA.png"));
      }
      };

      <RCC>
      <qresource prefix="/icons">
      <file alias="stateA.png">someFolder/someFile.png</file>
      <file alias="stateB.png">differentFolder/subFolder/someFile.png</file>
      ...
      </qresource>
      </RCC>
      @

      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