Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Setting default Application ICON (taskbar, .exe etc.)

Setting default Application ICON (taskbar, .exe etc.)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqtquickqt 6.1.3
3 Posts 2 Posters 6.7k 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.
  • M Offline
    M Offline
    Matthew0x
    wrote on last edited by
    #1

    Hello,

    I am trying to set an icon to my application in Qt 6.
    One can find that functionality in Visual Studio Projects when building Metro or WindowsForms apps.

    QtDefaultIcon.png
    [default taskbar icon]

    I have spent a few hours today searching for possible answers on Qt documentation pages, web queries etc.

    The best I could find was this result:
    https://doc-snapshots.qt.io/qt6-dev/appicon.html

    and some forum posts relating to this DOC page. I can't really understand what to do, according to the DOC.
    I believe that qmake is deprecated and Qt uses CMake, but I haven't used CMake and I have no idea what the guide is trying to describe.

    I have made my own Qt Resource Object:

    <!DOCTYPE RCC>
    <RCC version="1.0">
    <qresource>
         <file>Icons/AppIcon.svg</file>
     </qresource>
     </RCC>
    

    I gave a look the DOC on MS website, and RC files seem to be text files of some sort, but they don't provide any examples of how they may look like (how adorable).

    The .qrc (qt resource) has got a RCC tag inside, RCC isn't "RC", so this part of the guide
    "put a single line of text to the myapp.rc file:"

    IDI_ICON1               ICON    "myappico.ico"
    

    gets me confused. Where do I put it, if the entire file (.qrc) is written in Markup Language?

    I then tried to approach the CMake part of the guide.

    set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/photosurface.rc")
    qt_add_executable(photosurface main.cpp ${app_icon_resource_windows})
    
    set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/qt5app.rc")
    add_executable(qt5app main.cpp ${APP_ICON_RESOURCE_WINDOWS})
    

    Alright, but where do I set it in?
    I believe that .pro (project file) is the file that gets processed by qmake/CMake

    Alright, then the set() function takes a parameter that is an .RC file. How do I make an RC file?
    Also, the compiler says that it doesn't recognize "add_executable" and "set" functions (just ignoring the names inside the paths, because I don't have the .RC file anyway).

    QT += quick
    
    CONFIG += c++11
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    RESOURCES += qml.qrc \
        AppIcon.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/qt5app.rc")
    add_executable(qt5app main.cpp ${APP_ICON_RESOURCE_WINDOWS})
    
    

    I have however successfully set the tray icon using Tray Icon Object. This is actually bizarre, because setting this one was much easier than using an icon is.

    SystemTrayIcon {}
    

    Perhaps somebody faced an alike problem?

    PS: I removed the entire Qt instance today and reinstalled the newest version from the website (6.1.3).

    sierdzioS 1 Reply Last reply
    0
    • M Matthew0x

      Hello,

      I am trying to set an icon to my application in Qt 6.
      One can find that functionality in Visual Studio Projects when building Metro or WindowsForms apps.

      QtDefaultIcon.png
      [default taskbar icon]

      I have spent a few hours today searching for possible answers on Qt documentation pages, web queries etc.

      The best I could find was this result:
      https://doc-snapshots.qt.io/qt6-dev/appicon.html

      and some forum posts relating to this DOC page. I can't really understand what to do, according to the DOC.
      I believe that qmake is deprecated and Qt uses CMake, but I haven't used CMake and I have no idea what the guide is trying to describe.

      I have made my own Qt Resource Object:

      <!DOCTYPE RCC>
      <RCC version="1.0">
      <qresource>
           <file>Icons/AppIcon.svg</file>
       </qresource>
       </RCC>
      

      I gave a look the DOC on MS website, and RC files seem to be text files of some sort, but they don't provide any examples of how they may look like (how adorable).

      The .qrc (qt resource) has got a RCC tag inside, RCC isn't "RC", so this part of the guide
      "put a single line of text to the myapp.rc file:"

      IDI_ICON1               ICON    "myappico.ico"
      

      gets me confused. Where do I put it, if the entire file (.qrc) is written in Markup Language?

      I then tried to approach the CMake part of the guide.

      set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/photosurface.rc")
      qt_add_executable(photosurface main.cpp ${app_icon_resource_windows})
      
      set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/qt5app.rc")
      add_executable(qt5app main.cpp ${APP_ICON_RESOURCE_WINDOWS})
      

      Alright, but where do I set it in?
      I believe that .pro (project file) is the file that gets processed by qmake/CMake

      Alright, then the set() function takes a parameter that is an .RC file. How do I make an RC file?
      Also, the compiler says that it doesn't recognize "add_executable" and "set" functions (just ignoring the names inside the paths, because I don't have the .RC file anyway).

      QT += quick
      
      CONFIG += c++11
      
      # You can make your code fail to compile if it uses deprecated APIs.
      # In order to do so, uncomment the following line.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      SOURCES += \
              main.cpp
      
      RESOURCES += qml.qrc \
          AppIcon.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/qt5app.rc")
      add_executable(qt5app main.cpp ${APP_ICON_RESOURCE_WINDOWS})
      
      

      I have however successfully set the tray icon using Tray Icon Object. This is actually bizarre, because setting this one was much easier than using an icon is.

      SystemTrayIcon {}
      

      Perhaps somebody faced an alike problem?

      PS: I removed the entire Qt instance today and reinstalled the newest version from the website (6.1.3).

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Matthew0x said in Setting default Application ICON (taskbar, .exe etc.):

      The best I could find was this result:
      https://doc-snapshots.qt.io/qt6-dev/appicon.html

      and some forum posts relating to this DOC page. I can't really understand what to do, according to the DOC.
      I believe that qmake is deprecated and Qt uses CMake, but I haven't used CMake and I have no idea what the guide is trying to describe.

      You have a .pro file - this means you are using qmake. So as first step, ignore any tutorials and guides pertaining to cmake, they won't work for you.

      About qmake being deprecated - yes it is, but it will definitely NOT be removed in Qt 6 lifetime, which will probably be ~5 years. So don't worry.

      I have made my own Qt Resource Object:

      <!DOCTYPE RCC>
      <RCC version="1.0">
      <qresource>
           <file>Icons/AppIcon.svg</file>
       </qresource>
       </RCC>
      

      I gave a look the DOC on MS website, and RC files seem to be text files of some sort, but they don't provide any examples of how they may look like (how adorable).

      The .qrc (qt resource) has got a RCC tag inside, RCC isn't "RC", so this part of the guide
      "put a single line of text to the myapp.rc file:"

      IDI_ICON1               ICON    "myappico.ico"
      

      gets me confused. Where do I put it, if the entire file (.qrc) is written in Markup Language?

      Do not do this. As ther documentation suggests, you only need to add this in your .pro file:

      RC_ICONS = myappico.ico
      

      BTW. Notice the extension .ico - your SVG will not work! Windows only supports .ico format.

      I then tried to approach the CMake part of the guide.

      Nope, don't do it, you are using qmake.

      I have however successfully set the tray icon using Tray Icon Object. This is actually bizarre, because setting this one was much easier than using an icon is.

      Yes that's normal. Setting app icon is weird :-)

      At runtime you need to call QGuiApplication::instance()->setWindowIcon(QIcon("path/to/icon.png")); to decorate your window.

      Perhaps somebody faced an alike problem?

      Oh yes, every time I do an app on Windows :-D

      (Z(:^

      M 1 Reply Last reply
      3
      • sierdzioS sierdzio

        @Matthew0x said in Setting default Application ICON (taskbar, .exe etc.):

        The best I could find was this result:
        https://doc-snapshots.qt.io/qt6-dev/appicon.html

        and some forum posts relating to this DOC page. I can't really understand what to do, according to the DOC.
        I believe that qmake is deprecated and Qt uses CMake, but I haven't used CMake and I have no idea what the guide is trying to describe.

        You have a .pro file - this means you are using qmake. So as first step, ignore any tutorials and guides pertaining to cmake, they won't work for you.

        About qmake being deprecated - yes it is, but it will definitely NOT be removed in Qt 6 lifetime, which will probably be ~5 years. So don't worry.

        I have made my own Qt Resource Object:

        <!DOCTYPE RCC>
        <RCC version="1.0">
        <qresource>
             <file>Icons/AppIcon.svg</file>
         </qresource>
         </RCC>
        

        I gave a look the DOC on MS website, and RC files seem to be text files of some sort, but they don't provide any examples of how they may look like (how adorable).

        The .qrc (qt resource) has got a RCC tag inside, RCC isn't "RC", so this part of the guide
        "put a single line of text to the myapp.rc file:"

        IDI_ICON1               ICON    "myappico.ico"
        

        gets me confused. Where do I put it, if the entire file (.qrc) is written in Markup Language?

        Do not do this. As ther documentation suggests, you only need to add this in your .pro file:

        RC_ICONS = myappico.ico
        

        BTW. Notice the extension .ico - your SVG will not work! Windows only supports .ico format.

        I then tried to approach the CMake part of the guide.

        Nope, don't do it, you are using qmake.

        I have however successfully set the tray icon using Tray Icon Object. This is actually bizarre, because setting this one was much easier than using an icon is.

        Yes that's normal. Setting app icon is weird :-)

        At runtime you need to call QGuiApplication::instance()->setWindowIcon(QIcon("path/to/icon.png")); to decorate your window.

        Perhaps somebody faced an alike problem?

        Oh yes, every time I do an app on Windows :-D

        M Offline
        M Offline
        Matthew0x
        wrote on last edited by
        #3

        @sierdzio

        It worked as you said.

        Thank you for your help.

        I wish that it was possible to put different icons into a resource file, to be able to call upon any of them at a time.

        I put the ico file into my project folder and called it from .pro (project) file with that single line of code.
        It wasn't necessary to call any sort of function of window decoration (perhaps I haven't observed the issue yet). However, I believe that it was necessary to convert that file into .ico, what is ...

        well... the whole point of SVG is scalability, so that they look the same on any sort of device. I don't understand why Microsoft would stick to that .ico

        "...ICO files contain one or more small images at multiple sizes and color depths, such that they may be scaled appropriately."

        Perhaps it makes sense in some way. I simply spent more time poking around HTML 5.

        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