Results 1 to 5 of 5

Thread: Add icon to top left corner of all windows and taskbar icon

  1. #1
    Join Date
    Jan 2026
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Add icon to top left corner of all windows and taskbar icon

    I've been trying to get a custom icon I created to display in the top left corner of a Qt application I've been writing, and no matter what I try, I cannot get it to display. It will only display the default icon no matter what I do. I created a test app to try and just get it to work without doing it in my app, but even that won't work.
    I can get it to display the same icon within a window with QPixmap, so it's not a path issue.

    I've even tried deleting the Makefile created by qmake and the .qmake.stash files and running

    Qt Code:
    1. qmake test_icon.pro
    To copy to clipboard, switch view to plain text mode 

    again. But it still will not display my icon no matter what I try.

    I would like to display the same icon in all windows of my Qt app, as well as the taskbar icon as well.

    I'm new to programming with Qt, so I have no idea what I'm doing wrong.

    I'm using Manjaro Linux with Qt5.

    My main.cpp file:

    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QIcon>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8.  
    9. // Set the application icon using the resource path (:/myicon.png)
    10. app.setWindowIcon(QIcon(":/myicon.png"));
    11.  
    12. // Create main window (and any other windows)
    13. QMainWindow mainWindow;
    14. mainWindow.setWindowTitle("My App");
    15. mainWindow.show();
    16.  
    17. // Any other top-level windows you create will automatically use this icon
    18. // unless you set a different icon on them individually using setWindowIcon()
    19. // on the widget instance itself.
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    My resources.qrc file:

    Qt Code:
    1. <!DOCTYPE RCC>
    2. <RCC version="1.0">
    3. <qresource prefix="/">
    4. <file>myicon.png</file>
    5. </qresource>
    6. </RCC>
    To copy to clipboard, switch view to plain text mode 

    My test_icon.pro file:

    Qt Code:
    1. ######################################################################
    2. # Automatically generated by qmake (3.1) Fri Jan 16 16:35:33 2026
    3. ######################################################################
    4.  
    5. TEMPLATE = app
    6. TARGET = test_icon
    7. QT += widgets
    8. INCLUDEPATH += .
    9. RESOURCES += resources.qrc
    10.  
    11. # You can make your code fail to compile if you use deprecated APIs.
    12. # In order to do so, uncomment the following line.
    13. # Please consult the documentation of the deprecated API in order to know
    14. # how to port your code away from it.
    15. # You can also select to disable deprecated APIs only up to a certain version of Qt.
    16. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
    17.  
    18. # Input
    19. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    What in the f**king hell am I missing?? I don't understand what I'm doing wrong. I'm at my wits end with this.

    Can someone please tell me what I'm doing wrong in plain simple english?

    Thanks in advance for any help.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Add icon to top left corner of all windows and taskbar icon

    I am not all that familiar with various linux flavors, but quite often the window frame and its decorations are controlled by whatever window manager is being used for the PC desktop. This is the case for Windows.

    This bit from the Qt docs on Setting the Application Icon might provide more help.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2026
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Add icon to top left corner of all windows and taskbar icon

    Quote Originally Posted by d_stranz View Post
    I am not all that familiar with various linux flavors, but quite often the window frame and its decorations are controlled by whatever window manager is being used for the PC desktop. This is the case for Windows.

    This bit from the Qt docs on Setting the Application Icon might provide more help.
    Then why respond if you're "not familiar" with "linux flavors"? This isn't helpful. I'm not interested in Windows, that's not relevant.

    I've already looked at that and it's just confusing, as it mentions setIcon(); so what's the difference between setWindowIcon() and setIcon() ?
    What am I supposed to use, setIcon() or setWindowIcon() ?

    I'm sorry, but I don't understand what the difference between the two is, and the more I read, more confused I'm getting. Can someone please just explain it in plain simple english so I can understand it, please.

    Again, I'm new to Qt programming, so can someone who actually knows please enlighten me?

    Again, I'm trying to set a custom icon I created for top left corner of the window title bar (for all windows) and the icon displayed in the taskbar (being the same icon), instead of the default icon that's currently displayed. I would like to do this in code rather than using Qt Creator. Surely there must be a way to do this, and clearly I'm too thick to understand how to do it. Can someone please enlighten me in plain simple english.
    Last edited by why_bother; 16th January 2026 at 18:48.

  4. #4
    Join Date
    Jan 2026
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Add icon to top left corner of all windows and taskbar icon

    Can this thread be deleted? As I cannot find any option to do it myself. If it can't be, can a moderator please close it.

    I've decided to seek help elsewhere, as I think I'd get better help elsewhere.

    Sorry for the trouble.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Add icon to top left corner of all windows and taskbar icon

    I will close this thread at your request. I hope if you do look elsewhere for help, your rudeness in responding to an answer from someone trying to give you some help won't follow you there.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 13th February 2011, 21:24
  2. Replies: 4
    Last Post: 30th May 2010, 13:55
  3. Replies: 10
    Last Post: 29th May 2010, 19:42
  4. QTableWidget - Using top left corner cell
    By SteveH in forum Newbie
    Replies: 6
    Last Post: 12th March 2010, 20:33
  5. Replies: 1
    Last Post: 7th September 2008, 11:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.