how to set an icon on a Main window and action with QT

前端 未结 3 1207
滥情空心
滥情空心 2020-12-17 16:20

Honestly I do not understand resource files and how to get so that my things can get done, because it was partially explained to me and I\'m quite confused where to put icon

3条回答
  •  轮回少年
    2020-12-17 16:51

    Create a resources file named resources.qrc:

    
    
      path/to/icon.png
    
    
    

    Make sure that path/to/icon.png is an actual path, relative to the directory that contains resources.qrc.

    In your .pro file, include the resource:

    TARGET = your_app
    TEMPLATE = app
    QT += widgets 
    RESOURCES += path/to/resources.qrc
    

    Again, make sure that path/to/resources.qrc exists, relative to the directory that contains the project file.

    After compiling, your resource will be embedded into your executable. It can be accessed like:

    setWindowIcon(QIcon(":/path/to/icon.png"));
    

    If the icon is not appearing, try this stackoverflow question or this one.

    Another approach would be to use the Application Icon. This will set the application icon for your application on the desktop and start menus, and also on the top left corner of QMainWindows and QDialogs

提交回复
热议问题