"Go" Set QT application icon and application name

Source: Internet
Author: User

has been very tangled to the QT application to add icon problem, on-line received once, but feel not complete, is now the implementation of their own process to record, in order to view later:

Learn about the QT assistant in the online example:

Setting the application Icon

The application icon, typically displayed in the Top-left corner of a application ' s top-level windows, is set by calling Theqwidget::setwindowicon () method on top-level widgets.

In order to change the icon of the executable application file itself, as it was presented on the desktop (i.e., prior to a Pplication execution), it is necessary to employ another, platform-dependent technique.

Setting the application Icon on Windows

First, create an ICO format bitmap file contains the icon image. This can is done with e.g. Microsoft Visual C + +: Selectfile| New, then select the File tab in the dialog that appears, and choose Icon. (Note that you don't need to load your application into Visual C + +; Here we is only using the Icon editor.)

Store the ICO file in your application's source code directory, for example, with the name Myappico.ico. Then, create a text file called, say, myapp.rc in which you put a single line of text:

Idi_icon1               ICON    discardable     "Myappico.ico"

Finally, assuming you is using qmake to generate your makefiles, add the line to your Myapp.pro file:

Rc_file = myapp.rc

Regenerate your makefile and your application. The. exe file is now being represented with your icon in Explorer.

If you don't use qmake, the necessary steps Are:first, run the RC program on the . rc file, th En link your application with the resulting . Res file.

The method can be divided into two types from the above:

1. Use the Software method to set the default icon for the program window, but it cannot change the icon of the application file. exe.

2. Use the Qmake to generate makefile, such as QT+ECLIPSE,QT creator through the "If you don't use qmake" before the method can be resolved

3. Using qt+vs2010 is not the case with qmake, you need to execute the "If you don't use qmake ..." method, first add the. rc file to the project, then compile the. rc file, and finally reconnect to change the icon.

Implementation process:

1. Set the default icon for all Windows when the application runs.

[CPP]View Plaincopy
    1. Qapplication A (argc, argv);
    2. Get executable program Path
[CPP]View Plaincopy
    1. QString dir = Qapplication::applicationdirpath ();
    2. To set the executable path to the current working path
    3. Qdir::setcurrent (dir);
    4. Qapplication::addlibrarypath ("./plugins");
[CPP]View Plaincopy
    1. Qapplication::addlibrarypath ("./images");
    2. A.setwindowicon (Qicon ("./images/myappico.ico"));
2. Generate the Makefile implementation process via Qmake:

A. Find a picture. ico, name changed to Myappico.ico;

B. Create a new text document, add internal idi_icon1 ICON discardable "Myappico.ico", and rename the file to myapp.rc;

C. Add rc_file = myapp.rc at the end of the Myapp.pro file, and after rebuilding, the modification succeeds.
3. Do not qmake generate makefile implementation process:

As in the previous two steps, the last step is to load the. rc file into the project, right-click the project-add-existing file, add right-click. rc file compile, rebuild the executable and modify it successfully

"Go" Set QT application icon and application name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.