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. change icon of pushbutton

change icon of pushbutton

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 14.3k 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.
  • A Offline
    A Offline
    abhay
    wrote on last edited by
    #1

    Hello..I want to change the pushbutton icon when the user clicks on it.I mean like in the case of Vlc media player.When we click on pause the button,icon changes to play and vice versa.Can someone help me in this case? Thanks....

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @abhay Make the button checkable. Then when clicked check the checked state and then setIcon in the slot.
      Same can be done through stylesheet.

      157

      A 1 Reply Last reply
      4
      • p3c0P p3c0

        @abhay Make the button checkable. Then when clicked check the checked state and then setIcon in the slot.
        Same can be done through stylesheet.

        A Offline
        A Offline
        abhay
        wrote on last edited by
        #3

        @p3c0 I did the same what you said to.But the icons(images) are not appearing.What may be the problem?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @abhay Did it appear first time ?

          157

          A 1 Reply Last reply
          0
          • p3c0P p3c0

            @abhay Did it appear first time ?

            A Offline
            A Offline
            abhay
            wrote on last edited by
            #5

            @p3c0 Are you asking if it appared after changing my code?No.When I did it through stylesheet it appeared but icon is not changing and image is not looking good.When I click on it,it goes somewhat black and when I further click on it,it goes white(I mean color of the button).I think it is due to checkable property.But the images are not appearing at all(for the first time also).

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @abhay Post the code how you attempted to do it.

              157

              A 1 Reply Last reply
              0
              • p3c0P p3c0

                @abhay Post the code how you attempted to do it.

                A Offline
                A Offline
                abhay
                wrote on last edited by abhay
                #7

                @p3c0

                void SimplePlayer::on_fullscreen_clicked(bool checked)
                {
                
                    QIcon *ico = new QIcon();
                    ico->addPixmap(QPixmap("icons/icons/full_in.png"),QIcon::Normal,QIcon::On);
                    ico->addPixmap(QPixmap("icons/icons/full_out.png"),QIcon::Normal,QIcon::Off);
                    ui->fullscreen->setIcon(*ico);
                    ui->fullscreen->setCheckable(true);
                }
                
                

                This is my fullscreen function.I am using ui designer for buttons.

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  @abhay Are you sure the path is correct icons/icons ?
                  Is it in a resource file ?
                  Btw. you can avoid creating icon on heap.

                  157

                  A 1 Reply Last reply
                  0
                  • p3c0P p3c0

                    @abhay Are you sure the path is correct icons/icons ?
                    Is it in a resource file ?
                    Btw. you can avoid creating icon on heap.

                    A Offline
                    A Offline
                    abhay
                    wrote on last edited by
                    #9

                    @p3c0 Yeah.path is correct and it's in a resource file.What do you mean by Qicon on heap?

                    1 Reply Last reply
                    1
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #10

                      @abhay So if it is in a resource file then you need to prepend colon with the proper prefix. For eg. :/pix.png . Here the prefix is /

                      What do you mean by Qicon on heap?

                      Using new to create the instance. Alternatively you can do this:

                      QIcon ico;
                      ico.addPixmap(QPixmap(":/icons/icons/full_in.png"),QIcon::Normal,QIcon::On);
                      ui->fullscreen->setIcon(ico);
                      

                      157

                      A 1 Reply Last reply
                      4
                      • p3c0P p3c0

                        @abhay So if it is in a resource file then you need to prepend colon with the proper prefix. For eg. :/pix.png . Here the prefix is /

                        What do you mean by Qicon on heap?

                        Using new to create the instance. Alternatively you can do this:

                        QIcon ico;
                        ico.addPixmap(QPixmap(":/icons/icons/full_in.png"),QIcon::Normal,QIcon::On);
                        ui->fullscreen->setIcon(ico);
                        
                        A Offline
                        A Offline
                        abhay
                        wrote on last edited by
                        #11

                        @p3c0 Yeah..I am sorry.Found this solution just now.Thanks you very much for your solution !! :)

                        BramhaB 1 Reply Last reply
                        1
                        • A abhay

                          @p3c0 Yeah..I am sorry.Found this solution just now.Thanks you very much for your solution !! :)

                          BramhaB Offline
                          BramhaB Offline
                          Bramha
                          wrote on last edited by
                          #12

                          @abhay Please can you share the solution.

                          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