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. QPushButton changing between checkedOff / checkedOn .png graphics

QPushButton changing between checkedOff / checkedOn .png graphics

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

    Howdy,

    I have a QPushButton that has 2 .png images that switch between checkedOn / checkedOff states and change between each image when I click on it. Is there a way to switch images without clicking on it, for example using a QTimer?

    I wrote this pseudocode as an example:

    QTimer::singleShot(5000, this, &TestClass::switchButtonImage);
    
    void TestClass::switchButtonImage()
    {
    	QPixmap pixmap(":/button_ON.png");
    	QIcon buttonIcon(pixmap);
    	ui.button01->setIcon(buttonIcon);
    }
    
    JonBJ 1 Reply Last reply
    0
    • C Calicoder

      Howdy,

      I have a QPushButton that has 2 .png images that switch between checkedOn / checkedOff states and change between each image when I click on it. Is there a way to switch images without clicking on it, for example using a QTimer?

      I wrote this pseudocode as an example:

      QTimer::singleShot(5000, this, &TestClass::switchButtonImage);
      
      void TestClass::switchButtonImage()
      {
      	QPixmap pixmap(":/button_ON.png");
      	QIcon buttonIcon(pixmap);
      	ui.button01->setIcon(buttonIcon);
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Calicoder
      Did you try it? Looks reasonable to me.

      1 Reply Last reply
      2
      • C Offline
        C Offline
        Calicoder
        wrote on last edited by
        #3

        Tried it and it doesn't change the image. Only does so when I physically click on the button.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Do you mean just replace the image or programmatically change your button state ?

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

          C 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            Do you mean just replace the image or programmatically change your button state ?

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

            @SGaist Ohh interesting, I'm guessing changing the button state would end up changing the image displayed for the button?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Yes it will do the same as when you click on it.

              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
              1
              • C Offline
                C Offline
                Calicoder
                wrote on last edited by
                #7

                Perfect, thanks so much.

                ui.button01->setChecked(true);
                
                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