I am working with Qt to create a front-end for my application. Now I wanted to set an customized ICON for my application executable. I am using Qt 6.4. Already I create an resource file which it has .qrc format. Then I added my icon to that resource file. Now I wanted to know how can I set that icon file as executable icon. Is that possible somebody explain how can I set an customized icon for my application? Also I wanted to know how can I modify CMake to instruct compiler which executable should run with administrator privilege. Thank you.
Solution depends on your platform (Windows, mac, Linux) as well as your configuration tool (CMake, qmake).
Have a look at Qt documentation: https://doc.qt.io/qt-6/appicon.html. It tells what to do.
To achieve that, in my side, I'm doing 2 things :
1.
QApplication a(argc, argv);
a.setWindowIcon(QIcon(":/img/AppIcon.png"));
Create a resource.rc file with this content (have to possess a .ico version of the image)
IDI_ICON1 ICON DISCARDABLE "img/AppIcon.ico"
and declare in .pro
RC_FILE += \
resource.rc
Related
So I have a simple app that uses QML for my graphical interface and c++ code for some of the logic. I was looking for a method to compile the QML into c++ code and link it into my binary and found this page over at the Qt home site:
http://doc.qt.io/QtQuickCompiler/
Basically it says use the resource system for all of my QML graphical interface files and add the QML compiler flag to my qmake config line in my .pro file and everything should be good to go.
As far as I know everything compiles fine, but when I use the the Qt windeployqt.exe tool to get all of the dependency files and test it on a clean system, I get a small white screen as if my QML files were not loaded properly.
I have one c++ reference to my main QML file using "qrc:/mainqml.qml" and that's it.
Any idea what I am doing wrong?
You're using the open source version of Qt. It didn't come with the Qt Quick compiler until Qt 5.11 where it is included - and after a rework, too. So it performs better than precompiled QML did in Qt 5.10 and before.
I get a small white screen as if my QML files were not loaded properly.
... thus you need to deploy these files with the application, otherwise it won't work.
add the QML compiler flag to my qmake config
That flag was a no-op on an open source Qt build until Qt 5.11.
Qt Quick Compiler only shipped with Qt Commercial License, but you can still compile your QML files into qrc file. Starting a Qt Quick application project from Qt Creator does exactly this.
Deploying QML application with windeployqt require additional flag --qmldir, e.g.
windeployqt --(release or debug) --qmldir %PATH_TO_YOUR_QML_FILES% %YOUR_APPLICATION%.exe
It will parse your qml files and deploy all qml imports you used.
I use Qt in Visual Studio and I needed to set a tray icon in the application.
I use the next code:
QSystemTrayIcon trayIcon = new QSystemTrayIcon(this);
QIcon trayImage(":/Res/myIcon.ico");
trayIcon->setIcon(trayImage);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
My qrc file:
<RCC>
<qresource prefix="/">
<file>Res/myIcon.ico</file>
</qresource>
</RCC>
And it worked. But when I moved my application to another computer it failed with the error "This application failed to start because it could not find or load the Qt platform plugin 'windows'.". I solved it by creating the directory "platforms" in the directory with execution files and putting qwindows.dll in it. But after that the icon disappeared. I see only blank square in the tray. I can use tray icon actions but my image doesn't display.
Thanks for any idea why it happens.
When deploying Qt application to other machines, you'll also need to deploy plugins for the needed image formats. In your case you must create the imageformats directory and copy the qico.dll plugin (which can be found in the Qt SDK directory).
Nonetheless, I recommend using the PNG format for your tray icon in view of its better portability.
I read description of QIcon class, where you can find link to supported formats QImageReader::supportedImageFormats() and there is no .ico format.
I'm not sure, but probably it can be source of your problem. Try to change icon format to another one.
you should use one of the supported format of Image in qt. for example if you use .png format, it will shows.
I'm Confused about set the application icon.
I have seen many explanations about set the application icon, but I'm still not understand.
Please I want a simple explanation, but step by step to understand it
What I have done:
I have created a Qt resource file(.qrc).
Then, I have added a prefix, then I have added the Icon file.
Then, from design mode and from property block I have changed the a property called windowIcon.
Then I have selected the Icon which I added before in the .qrc file.
Notice: I'm use Qt5.3 and windows 7.
Now, Please what is the right steps to set the application icon ?
You have done the right thing to set the main window icon. Just setting windowIcon property in the designer will set an icon for the application window.
For setting an icon to the application executable file there is an automated process In Qt 5.
You can just add the following to the .pro file:
win32: RC_ICONS = myIcon.ico
Also store the .ico file in your application's source code directory.
Note that this is only for Windows. There are other ways to set application icon in Linux and Mac.
I have an MFC application. When the application is launched, I see it is represented on the taskbar using the MFC logo. Also, the application Window Menu Bar has the MFC icon.
How can I replace these with custom made logos?
The icons are in the .ico file that is part of your project. Usually in the /res directory. You can edit them or replace them with files you generate.
The icon file is stored with your project files.
Go to <Projects Folder>\SOLUTIONNAME\PROJECTNAME\res. When you locate this folder, there should be a PROJECTNAME.ico file. rename the ico file you created to PROJECTNAME.ico. Next time you build your project, the MFC icon should be replaced with your custom icon.
I recommend going to this site mostly because it does not require any registration and its 100% free.
You can then fine a suitable icon for your program bu searching keywords.
Then select the .ICO type and download.
Copy the .ico file to your “res” folder.
Then delete the .ico file and rename the downloaded file to .ico.
I'm reading the book "C++ GUI Programming with Qt4", and I've reached the topic of Integrating Custom Widgets with Qt Designer.
I've built the example project outlined there (the icon editor plugin), and I get a file called 'libiconeditorplugin.so', and I've copied it to '/usr/lib/qt4/plugins/designer/'. But when I start Qt Creator I don't see the icon editor widget in the widget box.
The only thing I've done differently from the book is I removed the DESTDIR from the .pro file because it had $QTDIR, and $QTDIR is not defined in my computer and I don't know where it should point. Instead, I copied the .so file manually.
I'm not sure if I've copied the plugin in the right directory, and if libiconeditorplugin.so is the only file that I needed to copy, the book was kind of sketchy on how it should work.
My OS is Ubuntu and I've installed Qt Creator with apt-get.
Turns out I was copying libiconeditorplugin.so to the wrong directory. I was copying it to "/usr/lib/qt4/plugins/designer/", while Qt Designer was looking in "/usr/lib/x86_64-linux-gnu/qt4/plugins/designer/".