Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QIcon, how to set it from code?

    General and Desktop
    3
    7
    2109
    Loading More Posts
    • 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.
    • VrtniPatuljak
      VrtniPatuljak last edited by

      Hi everyone,

      I want to create GUI application for basic text file manipulation. My application up to now has 4 simple QPushButtons: load, save, save-as and exit. My goal is to set up default icons on them. I use Linux Mint 17.

      What is a real problem: When I go in QtDesigner, click on pushbutton I can simply write under "Theme" bar: "document-open" and it will load Icon for document open. However when I put in my code next line:

      QIcon saveAs = QIcon::fromTheme("document-save-as");
      ui->SaveAsFileBtn->setIcon(saveAs);

      it does not change icon. I assume that the problem is my theme. Can anyone please help me how to set up these Icons.

      thank you in advance

      raven-worx 1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Are you sure your theme provides such an icon ?

        You can check with the isNull method.

        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 Reply Quote 0
        • VrtniPatuljak
          VrtniPatuljak last edited by VrtniPatuljak

          Thank you on warm welcome,

          You were correct it is null but I am confused now a lot. What bothers me is next:

          For instance:
          In Qt Designer I drag QPushButton and open his properties. Next I navigate to Icon property and start writing in tab "Theme" : document-open or document-save and some kind of icon is showing in tab icon. My question is how to use that icon?

          My english is not the best-but I hope you guys know what I mean.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            It might be that the current theme you are using doesn't provide an icon for "document-save-as"

            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 Reply Quote 0
            • raven-worx
              raven-worx Moderators @VrtniPatuljak last edited by raven-worx

              @VrtniPatuljak
              maybe it helps setting the theme explicitly using QIcon::setThemeName("THEME-NAME").

              QtDoc:

              The name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing it's contents.

              Check the search paths on your system and see what they actually contain.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply Reply Quote 0
              • VrtniPatuljak
                VrtniPatuljak last edited by VrtniPatuljak

                It have "document-save-as" icon, it display it in the QT designer.

                I try also QIcon::setThemeName() but unfortunately it did not give any positive results. QIcon::themeSearchPath() gives me "/usr/share/icons/" directory, but there are many themes inside :/ I don't know how to choose correct one. Is there a way to find what theme is currently active on my desktop?

                1 Reply Last reply Reply Quote 0
                • VrtniPatuljak
                  VrtniPatuljak last edited by VrtniPatuljak

                  Ok, so here how I did it.

                  I literally search for icon path, first of all I have found what theme my OS is currently using. Then I found where are my Icons stored, after that I have found my icon.

                  
                  std::string search = QIcon::themeSearchPaths()[0].toStdString();
                  std::string out = GetStdoutFromCommand("gsettings list-recursively | grep icon-theme ");
                  std::vector <int> positions;
                  for (int i = 0; i < out.size();++i)
                          if (out[i] == '\'') positions.push_back(i);
                  
                  int p1 = positions[positions.size()-1], p2 = positions[positions.size()-2];
                  p2=p2+1;
                  std::string theme = out.substr(p2,p1-p2);
                  search +="/";
                  std::string path;
                  
                  path = "find "+search+theme+"/* -iname document-open.png | grep '32'";
                  std::string icon_open = GetStdoutFromCommand(path);
                  

                  Many parsing is done but I think that generally idea is ok. And also here is the code to capture bash command output: GetStdoutFromCommand

                  1 Reply Last reply Reply Quote -1
                  • First post
                    Last post