I have some buttons on a tabwidget. These buttons need to have some icon on top of them.
I am aware of QPixmap that will allow me to put an image on top of a button, but I see that these constructors take a filepath as a parameter. I want to avoid dragging icons around in a file after I build. I would like to embed these icons in the executeable somehow, so as to reduce the baggage that I need to lug around in order to make it work.
How can I accomplish this?
I am interested in hearing ways to accomplish my goal of not needing to drag icon files around with the executable; please focus on this aspect if you are confused about some terminology I may have used, as I am still learning Qt.
This can be done using Microsoft Visual Studio: Select File >> New, and choose the Icon File. Note: You need not load the application into the Visual Studio IDE as you are using the icon editor only. Store the ICO file in your application's source code directory, for example, with the name appico.
To create a pixmap from the file, we need to first create an image and then convert this image into a pixmap using QPixmap::fromImage(). Once we have the final pixmap, we add it, with its associated mode and state, to the QIcon's set of available pixmaps. previewArea->setIcon(icon);
Of course you can embed icons, images and all other custom resources into your application. Please read The Qt 4's Resource System (or click here for Qt 5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With