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. How to change the icon of the actions on ToolBar during runtime?
Forum Updated to NodeBB v4.3 + New Features

How to change the icon of the actions on ToolBar during runtime?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.3k Views 3 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.
  • sheeleyS Offline
    sheeleyS Offline
    sheeley
    wrote on last edited by SGaist
    #1

    I want to design an action, like the control buttons of a media player, when I click the start button, the button becomes a pause button.
    I have set the default action icon, when I try to change it, use codes following:
    ui->actionConnect->setIcon(QIcon(":/resources/disconnect.ico"));
    I found the icon will become empty.
    So what's the right method? :(

    I like programming :)

    R 1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      That should do it. Are you sure the path is correct?

      sheeleyS 1 Reply Last reply
      0
      • sheeleyS sheeley

        I want to design an action, like the control buttons of a media player, when I click the start button, the button becomes a pause button.
        I have set the default action icon, when I try to change it, use codes following:
        ui->actionConnect->setIcon(QIcon(":/resources/disconnect.ico"));
        I found the icon will become empty.
        So what's the right method? :(

        R Offline
        R Offline
        raf924
        wrote on last edited by
        #3

        @sheeley The icon file must be JPG or PNG

        Chris KawaC 1 Reply Last reply
        -1
        • R raf924

          @sheeley The icon file must be JPG or PNG

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @raf924 No. It doesn't. It can be any of the supported image formats or anything that you add via imageformat plugin.

          R 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            @raf924 No. It doesn't. It can be any of the supported image formats or anything that you add via imageformat plugin.

            R Offline
            R Offline
            raf924
            wrote on last edited by
            #5

            @Chris-Kawa Yes yes you're right i misspoke. what i meant was that it would work with another format by giving two widely-used formats. But indeed it would work with the formats given in the link

            1 Reply Last reply
            0
            • Chris KawaC Chris Kawa

              That should do it. Are you sure the path is correct?

              sheeleyS Offline
              sheeleyS Offline
              sheeley
              wrote on last edited by sheeley
              #6

              @Chris-Kawa Thanks for your reply.
              The folder tree is as follows:
              Project Folder
              .....mainWindow.cpp
              .....others cpp files
              .....resources <- This is a folder.
              ..........disconnect.ico

              The codes above are in the mainWindpw.cpp, so was the path right?

              I like programming :)

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

                Hi,

                Did you put disconnect.ico in Qt's resource system ? Otherwise that's the first problem you have with the path you used in you sample code.

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

                sheeleyS 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Did you put disconnect.ico in Qt's resource system ? Otherwise that's the first problem you have with the path you used in you sample code.

                  sheeleyS Offline
                  sheeleyS Offline
                  sheeley
                  wrote on last edited by
                  #8

                  @SGaist Thank you.
                  I mistook the resources prefix. It works now.

                  I like programming :)

                  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