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. setWindowIcon only works once?
Forum Updated to NodeBB v4.3 + New Features

setWindowIcon only works once?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 4.5k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Please you show the code you are using for that.
    Also:

    • What version of Qt are you using ?
    • On what platform ?

    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
    • S Offline
      S Offline
      Slei
      wrote on last edited by Slei
      #3

      @SGaist
      I'm using setWindowIcon(..)
      m_application->setWindowIcon(icon);

      the icon variable works for the systemtray icon, but doesn't work form setWindowIcon, so I'm passing the correct QIcon to the setWindowIcon function

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

        Are you using the same icon variable for setWindowIcon then for the system tray ?

        You omitted to answer two questions.

        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
        • S Offline
          S Offline
          Slei
          wrote on last edited by Slei
          #5

          @SGaist

          The issues exists on Windows.

          And yes it is the same QIcon variable, I've tried to manually change it with different QIcons but nothing happens

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #6

            Can you show me how you are getting the object m_application ? Are you creating it ?

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Slei
              wrote on last edited by Slei
              #7

              @dheerendra

              I'm creating the object my self in an custom object which is created in the main.cpp:

              ``
              

              MyApp.h
              std::unique_ptr<QApplication> m_application;

              MyApp.cpp
              m_application = std::make_unique<QApplication>(argc,
              argv);

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #8

                show me your main.cpp ?

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Slei
                  wrote on last edited by Slei
                  #9

                  @dheerendra ```

                  int main(int argc, char *argv[])
                  {
                  MyApp a(argc, argv);
                  MainWindow w;
                  w.show();

                  //this just uses the QApplication exec
                  return a.exec();
                  }

                  
                  In generall i'm actually using the MyApp just as it would be a QApplication directly nothing special,
                  1 Reply Last reply
                  0
                  • dheerendraD Offline
                    dheerendraD Offline
                    dheerendra
                    Qt Champions 2022
                    wrote on last edited by
                    #10

                    MyApp is inherited from QApplication ?

                    Dheerendra
                    @Community Service
                    Certified Qt Specialist
                    http://www.pthinks.com

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Slei
                      wrote on last edited by Slei
                      #11

                      @dheerendra
                      no it just has a QApplication member and has similar member functions(like exec)

                      MyApp.h
                      std::unique_ptr<QApplication> m_application;

                      1 Reply Last reply
                      0
                      • dheerendraD Offline
                        dheerendraD Offline
                        dheerendra
                        Qt Champions 2022
                        wrote on last edited by
                        #12

                        My suspect was you have two different instances of QApplication and could be causing the issue. Looks like this is not issue.

                        I tried on Windows & Mac. It works without any issue. Can you try the following sample?

                        void MyWidget::on_pushButton_clicked()
                        {
                        qDebug() << Q_FUNC_INFO << endl;
                        qApp->setWindowIcon(QIcon(":/Phone_1.jpg"));
                        }

                        void MyWidget::on_pushButton_2_clicked()
                        {
                        qDebug() << Q_FUNC_INFO << endl;
                        qApp->setWindowIcon(QIcon(":/RightOption.png"));
                        }
                        ==========main.cpp =========

                        QApplication a(argc, argv);
                        a.setWindowIcon(QIcon(":/Air.png"));
                        MyWidget w;
                        w.show();
                        

                        Dheerendra
                        @Community Service
                        Certified Qt Specialist
                        http://www.pthinks.com

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Slei
                          wrote on last edited by Slei
                          #13

                          @dheerendra
                          I'm using QML instead of QWidget for the gui app, might there be any issue?

                          1 Reply Last reply
                          0
                          • dheerendraD Offline
                            dheerendraD Offline
                            dheerendra
                            Qt Champions 2022
                            wrote on last edited by dheerendra
                            #14

                            Yes. it is issue with QML application. It is bug. It should work the same way. Issue is coming from application object. Instead of using the application object to change with window icon, we can use the top-level window object & use the setIcon(...) method to set it. It should work.

                            Dheerendra
                            @Community Service
                            Certified Qt Specialist
                            http://www.pthinks.com

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Slei
                              wrote on last edited by
                              #15

                              Ok Its working now, the issue was indeed QML, now I'Ve just the QQuickWindow as base class for my QML window and use its seticon function on each window instead of using the QApplication setWindowicon

                              1 Reply Last reply
                              0
                              • dheerendraD Offline
                                dheerendraD Offline
                                dheerendra
                                Qt Champions 2022
                                wrote on last edited by
                                #16

                                That is good. You can move the issue to "Solved" state. Enjoy the Qt Programming.

                                Dheerendra
                                @Community Service
                                Certified Qt Specialist
                                http://www.pthinks.com

                                1 Reply Last reply
                                1

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved