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. Maybe im to dumb, but i cant get the icons to work.
Qt 6.11 is out! See what's new in the release blog

Maybe im to dumb, but i cant get the icons to work.

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 3 Posters 822 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.
  • MSC615M Offline
    MSC615M Offline
    MSC615
    wrote last edited by MSC615
    #1

    Hello,
    first i want to say that am not good in C++ coding, but C++ was the best option for my use case I think.
    Second, i'm new to Qt Creator, but not to Qt Designer, so i'm better at designing the stuff than actually making the whole software.
    Third, doing things with tech is my hobby, and i learn the things i need to learn for it by doing it or from the help i get in forums.

    And now to the reason why I'm writing this: I'm trying to create a MP3-Player software from scratch for my Raspberry Pi to use it as one. Here is the design(screenshot of the preview beside the design in the designer): 5339b01b-1cc2-4cd2-9bfa-e9479fe12e56-image.png (dont mind the background, i'm a murder drones fan )

    As you can see, the icons are missing. And that's the problem. I wanted to implement folder-based Icon Themes(in the project folder is a folder named "iconThemes" that contains the folders with the icons), and the only thing i got to work was the ComboBox in the pageSettings to display the folder names and let me choose one to choose the theme. But i tried to also implement the thing that the icons should be loaded, but it wont work!
    (If anyone wonders, yes I am a kid, 16 years old, and yes, I may be dumb as hell. And any working help will also help me get better and understanding C++ better.)

    If anyone knows how to fix my problems, it would be awesome if you help me, and if I put this in the wrong Category, just tell me because I didn't had a clue in what Category i should put this.

    And a little thing that's a little bit off-topic: i also couldn't get the Widget QWebEngineView working, the code doesn't know how to use it and i don't know what lib i should use to get it to work because I didn't find one(or i was to blind).

    Qt Creator Version: 19.0.2
    Qt Version: 6.11.1
    Platform: Linux, CachyOS
    Installed via: terminal (sudo pacman -S qtcreator)

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

      I suspect that your setTheme function is where you update all the icons, right ?
      So it's there that you should use the example path creation.

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

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

        Hi and welcome to devnet,

        No worries, we all started somewhere and had to learn.
        Which format are the images you want to use for your icons ?
        How are you setting them in your code ?

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

        MSC615M 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          No worries, we all started somewhere and had to learn.
          Which format are the images you want to use for your icons ?
          How are you setting them in your code ?

          MSC615M Offline
          MSC615M Offline
          MSC615
          wrote last edited by
          #3

          @SGaist somehow i cant reply over my laptop with parts of code. Yea to be honest a lot of code because it includes the whole rpimp3.h and stuff from the cpp file but it marks it as spam all the time.

          MSC615M 1 Reply Last reply
          0
          • MSC615M MSC615

            @SGaist somehow i cant reply over my laptop with parts of code. Yea to be honest a lot of code because it includes the whole rpimp3.h and stuff from the cpp file but it marks it as spam all the time.

            MSC615M Offline
            MSC615M Offline
            MSC615
            wrote last edited by MSC615
            #4

            @SGaist 1000039076.png see that? Do you know why?

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

              Are you using relative path to load your icons ?
              I suppose they are in your sources but the binary is started in the build folder so if you are using a path relative to your application binary location, that will be your main issue.

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

              MSC615M 1 Reply Last reply
              1
              • SGaistS SGaist

                Are you using relative path to load your icons ?
                I suppose they are in your sources but the binary is started in the build folder so if you are using a path relative to your application binary location, that will be your main issue.

                MSC615M Offline
                MSC615M Offline
                MSC615
                wrote last edited by
                #6

                @SGaist i unserstand 50% of the thing you said. Im pulling thd cons from the projectforder(rpimp3)/iconThemes/ and then there are the folders containing the icons.

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

                  So I think we are on the right track.
                  Can you print and paste here the path that you pass to create the QIcon ?

                  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
                  0
                  • Joe von HabsburgJ Offline
                    Joe von HabsburgJ Offline
                    Joe von Habsburg
                    wrote last edited by
                    #8

                    As far as I understand, you want to add icons to the buttons here

                    9e45dbb8-a432-406c-8971-26ceb2e56750-image.png

                    To do this, you first need to add a resources file to your project

                    a6407905-e89f-4481-95a2-77202252e5b0-image.png

                    Then, in Qt Creator, you can right-click the xxx.qrc file and select “Open in Editor.

                    67aa4602-e39f-450f-bff7-8eb58e7782d2-image.png

                    First, you need to add a prefix; I usually just use “/” because I organize them into folders. Then you can add your images by clicking “Add Files.”

                    You can also add the icons by selecting them from the “Choose Resources” section in the UI.

                    2ec1f1c9-6fa3-43f5-b6c6-8ab11c74201d-image.png

                    MSC615M 1 Reply Last reply
                    0
                    • Joe von HabsburgJ Joe von Habsburg

                      As far as I understand, you want to add icons to the buttons here

                      9e45dbb8-a432-406c-8971-26ceb2e56750-image.png

                      To do this, you first need to add a resources file to your project

                      a6407905-e89f-4481-95a2-77202252e5b0-image.png

                      Then, in Qt Creator, you can right-click the xxx.qrc file and select “Open in Editor.

                      67aa4602-e39f-450f-bff7-8eb58e7782d2-image.png

                      First, you need to add a prefix; I usually just use “/” because I organize them into folders. Then you can add your images by clicking “Add Files.”

                      You can also add the icons by selecting them from the “Choose Resources” section in the UI.

                      2ec1f1c9-6fa3-43f5-b6c6-8ab11c74201d-image.png

                      MSC615M Offline
                      MSC615M Offline
                      MSC615
                      wrote last edited by
                      #9

                      @Joe-von-Habsburg b0d974d9-239d-4669-aafe-778760ede943-20260603150625.png /home/msc615/Pictures/Screenshots/20260603150625.png
                      i dont know what you meant and how i add the recources.grc(or what it is) file, but i did that a little bit in the past: add existing files. and just so you know: i want changable icons, by choosing the theme in the settings->apperance tab of my app, so i dont know how that would be made possible with the thing you said.

                      Joe von HabsburgJ 1 Reply Last reply
                      0
                      • MSC615M MSC615

                        @Joe-von-Habsburg b0d974d9-239d-4669-aafe-778760ede943-20260603150625.png /home/msc615/Pictures/Screenshots/20260603150625.png
                        i dont know what you meant and how i add the recources.grc(or what it is) file, but i did that a little bit in the past: add existing files. and just so you know: i want changable icons, by choosing the theme in the settings->apperance tab of my app, so i dont know how that would be made possible with the thing you said.

                        Joe von HabsburgJ Offline
                        Joe von HabsburgJ Offline
                        Joe von Habsburg
                        wrote last edited by Joe von Habsburg
                        #10

                        @MSC615 said in Maybe im to dumb, but i cant get the icons to work.:

                        i dont know what you meant and how i add the recources.grc(or what it is) file

                        If you read

                        @Joe-von-Habsburg said in Maybe im to dumb, but i cant get the icons to work.:

                        o do this, you first need to add a resources file to your project

                        I told step by step.

                        I'm not quite sure what you mean by “changable icons.” Do you want to change the icon itself, or the button color?

                        If you want to change the icon, you'll need to upload your images to the xxx.qrc file, just as I explained above.

                        After uploading your photos as described above, here’s what you need to do.

                        void MainWindow::on_comboBox_currentIndexChanged(int index)
                        {
                            if(index == 0){
                               ui->spotify->setIcon(QIcon(QPixmap(":/Resources/images/spotify_black.png"));
                            }
                            else if (index == 1){
                               ui->spotify->setIcon(QIcon(QPixmap(":/Resources/images/spotify_red.png"));
                            }
                            ...
                        }
                        
                        

                        you need "xxx.qrc" file

                        If you want to change only button color, same steps

                        void MainWindow::on_comboBox_currentIndexChanged(int index)
                        {
                            if(index == 0){
                               ui->spotify->setStyleSheets("background-color:black;");
                            }
                            else if (index == 1){
                               ui->spotify->setStyleSheets("background-color:red;");
                            }
                            ...
                        }
                        
                        

                        If you change icon color. I do not know how it is work in qt. Maybe SVG module helps

                        MSC615M 1 Reply Last reply
                        0
                        • Joe von HabsburgJ Joe von Habsburg

                          @MSC615 said in Maybe im to dumb, but i cant get the icons to work.:

                          i dont know what you meant and how i add the recources.grc(or what it is) file

                          If you read

                          @Joe-von-Habsburg said in Maybe im to dumb, but i cant get the icons to work.:

                          o do this, you first need to add a resources file to your project

                          I told step by step.

                          I'm not quite sure what you mean by “changable icons.” Do you want to change the icon itself, or the button color?

                          If you want to change the icon, you'll need to upload your images to the xxx.qrc file, just as I explained above.

                          After uploading your photos as described above, here’s what you need to do.

                          void MainWindow::on_comboBox_currentIndexChanged(int index)
                          {
                              if(index == 0){
                                 ui->spotify->setIcon(QIcon(QPixmap(":/Resources/images/spotify_black.png"));
                              }
                              else if (index == 1){
                                 ui->spotify->setIcon(QIcon(QPixmap(":/Resources/images/spotify_red.png"));
                              }
                              ...
                          }
                          
                          

                          you need "xxx.qrc" file

                          If you want to change only button color, same steps

                          void MainWindow::on_comboBox_currentIndexChanged(int index)
                          {
                              if(index == 0){
                                 ui->spotify->setStyleSheets("background-color:black;");
                              }
                              else if (index == 1){
                                 ui->spotify->setStyleSheets("background-color:red;");
                              }
                              ...
                          }
                          
                          

                          If you change icon color. I do not know how it is work in qt. Maybe SVG module helps

                          MSC615M Offline
                          MSC615M Offline
                          MSC615
                          wrote last edited by
                          #11

                          @Joe-von-Habsburg

                          @Joe-von-Habsburg said in Maybe im to dumb, but i cant get the icons to work.:

                          'm not quite sure what you mean by “changable icons.”

                          with that i meant changable icons, like icon themes but with custom icons. im planning to go with two themes, and other users can simply create their own and paste them i the iconTheme folder.

                          1 Reply Last reply
                          0
                          • Joe von HabsburgJ Offline
                            Joe von HabsburgJ Offline
                            Joe von Habsburg
                            wrote last edited by
                            #12

                            I still do not understan what you want.

                            Do you want like that ?

                            39937146-0a30-41e7-8686-25456ac1c3e7-image.png

                            If it is, you need add black and red icon together.
                            If you want to change ICON COLOR, i do not know how, please look SVG module. Maybe help you

                            MSC615M 1 Reply Last reply
                            0
                            • Joe von HabsburgJ Joe von Habsburg

                              I still do not understan what you want.

                              Do you want like that ?

                              39937146-0a30-41e7-8686-25456ac1c3e7-image.png

                              If it is, you need add black and red icon together.
                              If you want to change ICON COLOR, i do not know how, please look SVG module. Maybe help you

                              MSC615M Offline
                              MSC615M Offline
                              MSC615
                              wrote last edited by
                              #13

                              @Joe-von-Habsburg no, i have like a icon for the recorder app(only a example) in the Nothing Phone style, and one in (this is my plan) Murder drones style. it doesnt only change some colors, it also adds new things like a gliched-out-organic-fleshy-ripped-arm-thingy (typical Murder drones stuff) that grabs a bar of the icon recorder.png ( thats the Nothing styled icon, needed to convert it do png to upload) and therefore the bar is a bit of and rotated to the side or completly ripped out(i know a lot of text, i didnt know how to describe it else). thats what i planned. the icon theme folders are located in the project folder and have the path(after the folder that contains other things that i might add as icons or other things) /rpimp3/iconThemes and currently there are these icon theme folders(the second is currently empty because im ass at designing murder drones stuff) : NothingTheme and MDTheme. a bit confusing how i explained it i think, but take some time understanding my sometimes random gibberish to know what i mean.

                              1 Reply Last reply
                              0
                              • Joe von HabsburgJ Offline
                                Joe von HabsburgJ Offline
                                Joe von Habsburg
                                wrote last edited by Joe von Habsburg
                                #14

                                You have iconThemes folder.
                                In the iconThemes you have NothingTheme folder.
                                NothingTheme folder has icons.

                                there is ok.

                                iconThemes can be has ABCTheme folder.
                                and ABCTheme folder has same icons but different styles.

                                If I understand true. You want to like that ?

                                now You say :
                                1 - I want to change theme. when theme change icon change.
                                2 - User can add own icon theme folder.

                                Solution for Question 1 :

                                add icon to xxx.qrc file

                                void MainWindow::on_comboBox_currentTextChanged(QString text)
                                {
                                    ui->spotify->setIcon(QIcon(QPixmap(QString(":/iconThemes/%1/spotify.png").arg(text)));
                                    ...
                                }
                                

                                That must be work.

                                Solution for Question 2 :

                                you need list in iconThemes folder folders. and add to combox on start. also custom themes folder have to have icons with same name.

                                NOTE :
                                You may need to copy the “themefolder” folder to the “exe” folder. This way, you can access the file directory without using QRC. It will be easier for you.

                                MSC615M Joe von HabsburgJ 2 Replies Last reply
                                0
                                • Joe von HabsburgJ Joe von Habsburg

                                  You have iconThemes folder.
                                  In the iconThemes you have NothingTheme folder.
                                  NothingTheme folder has icons.

                                  there is ok.

                                  iconThemes can be has ABCTheme folder.
                                  and ABCTheme folder has same icons but different styles.

                                  If I understand true. You want to like that ?

                                  now You say :
                                  1 - I want to change theme. when theme change icon change.
                                  2 - User can add own icon theme folder.

                                  Solution for Question 1 :

                                  add icon to xxx.qrc file

                                  void MainWindow::on_comboBox_currentTextChanged(QString text)
                                  {
                                      ui->spotify->setIcon(QIcon(QPixmap(QString(":/iconThemes/%1/spotify.png").arg(text)));
                                      ...
                                  }
                                  

                                  That must be work.

                                  Solution for Question 2 :

                                  you need list in iconThemes folder folders. and add to combox on start. also custom themes folder have to have icons with same name.

                                  NOTE :
                                  You may need to copy the “themefolder” folder to the “exe” folder. This way, you can access the file directory without using QRC. It will be easier for you.

                                  MSC615M Offline
                                  MSC615M Offline
                                  MSC615
                                  wrote last edited by
                                  #15
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • Joe von HabsburgJ Joe von Habsburg

                                    You have iconThemes folder.
                                    In the iconThemes you have NothingTheme folder.
                                    NothingTheme folder has icons.

                                    there is ok.

                                    iconThemes can be has ABCTheme folder.
                                    and ABCTheme folder has same icons but different styles.

                                    If I understand true. You want to like that ?

                                    now You say :
                                    1 - I want to change theme. when theme change icon change.
                                    2 - User can add own icon theme folder.

                                    Solution for Question 1 :

                                    add icon to xxx.qrc file

                                    void MainWindow::on_comboBox_currentTextChanged(QString text)
                                    {
                                        ui->spotify->setIcon(QIcon(QPixmap(QString(":/iconThemes/%1/spotify.png").arg(text)));
                                        ...
                                    }
                                    

                                    That must be work.

                                    Solution for Question 2 :

                                    you need list in iconThemes folder folders. and add to combox on start. also custom themes folder have to have icons with same name.

                                    NOTE :
                                    You may need to copy the “themefolder” folder to the “exe” folder. This way, you can access the file directory without using QRC. It will be easier for you.

                                    Joe von HabsburgJ Offline
                                    Joe von HabsburgJ Offline
                                    Joe von Habsburg
                                    wrote last edited by
                                    #16

                                    @Joe-von-Habsburg said in Maybe im to dumb, but i cant get the icons to work.:

                                    You may need to copy the “themefolder” folder to the “exe” folder. This way, you can access the file directory without using QRC. It will be easier for you.

                                    follow that way.

                                    for : resouces file add
                                    Right Click your project -> add new file -> qt -> qt resources file

                                    MSC615M 1 Reply Last reply
                                    0
                                    • Joe von HabsburgJ Joe von Habsburg

                                      @Joe-von-Habsburg said in Maybe im to dumb, but i cant get the icons to work.:

                                      You may need to copy the “themefolder” folder to the “exe” folder. This way, you can access the file directory without using QRC. It will be easier for you.

                                      follow that way.

                                      for : resouces file add
                                      Right Click your project -> add new file -> qt -> qt resources file

                                      MSC615M Offline
                                      MSC615M Offline
                                      MSC615
                                      wrote last edited by
                                      #17

                                      @Joe-von-Habsburg ok, got it, qrc file is in. Now i did add prefix and typed / as prefix, should i also type something in the Lang thing and alias?

                                      1 Reply Last reply
                                      0
                                      • Joe von HabsburgJ Offline
                                        Joe von HabsburgJ Offline
                                        Joe von Habsburg
                                        wrote last edited by
                                        #18

                                        There's no need; I think you can leave it as “/” in the prefix section because you're creating subfolders within the folder.

                                        To reiterate, you may need to copy it into the EXE folder, or create a folder in another location—such as the Documents folder—and place it there. I’m mentioning this because users can add their own themes. This is because the resources file is compiled along with your application.

                                        MSC615M 1 Reply Last reply
                                        0
                                        • Joe von HabsburgJ Offline
                                          Joe von HabsburgJ Offline
                                          Joe von Habsburg
                                          wrote last edited by Joe von Habsburg
                                          #19

                                          I think you generally understand what you need to do. Create a folder in a location accessible to the user, check that location when the app launches, and add the themes to the combo box or another location to apply the changes.

                                          The QRC file is necessary for this reason. If the theme folder is missing, the default theme stored there will be used. So it’s not entirely unnecessary.

                                          1 Reply Last reply
                                          0
                                          • Joe von HabsburgJ Joe von Habsburg

                                            There's no need; I think you can leave it as “/” in the prefix section because you're creating subfolders within the folder.

                                            To reiterate, you may need to copy it into the EXE folder, or create a folder in another location—such as the Documents folder—and place it there. I’m mentioning this because users can add their own themes. This is because the resources file is compiled along with your application.

                                            MSC615M Offline
                                            MSC615M Offline
                                            MSC615
                                            wrote last edited by
                                            #20

                                            @Joe-von-Habsburg ok, that means if people want to add their own themes, they need to edit the qrc file? or can i do like i tried to that the code recognizes new folders in the icon themes folder and uses the icons in there?(and holy frick, i need to do a lot to make it easy for others to use it. i also need to make it compatible to my Raspberry Pi 4B with frickin 1GB RAM and 3GB swap. thats gonna be a journey!

                                            Joe von HabsburgJ 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