I want a series of buttons <>^V (left, right, up, down). How do I create a button with only an icon/image, on it? When I use the QPushButton(icon, text) constructor all I get is the text.
- Bruce
I want a series of buttons <>^V (left, right, up, down). How do I create a button with only an icon/image, on it? When I use the QPushButton(icon, text) constructor all I get is the text.
- Bruce
One possibility is to use QToolButton and it's built-in arrow type property.
J-P Nurmi
I was attempting to use a 'gif" file. Once I converted it to a jpg file, it worked. I even gave the "gif" as the file type. The problem is, the file type for the load() API is not well documented. I couldn't tell what valid formats are handled on Windows and which are not. Anyway, once I converted the gifs to jpgs, it seems to work.
Thanks for your help.
- Bruce
I will also consider using the QToolButton as well in the future.
Again, thanks for your help
- Bruce
bruccutler (19th January 2007)
Are you sure the QIcon you pass in QPushButton has its image loaded? The following code should work:
Qt Code:
#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { pushButton->show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Please check that the path to the icon is valid (or better use the resource system of Qt). Next you may try it without the text and set the QPushButton's flat-property to true (might look better with icon-only buttons).
I still would like to know why it failed to load the .gif file when it succeeded with the .jpg. But for now, I'm moving on.
Thanks for all the help.
- Bruce
Qt doesn't support GIF by default, due to licensing issues. You have to recompile Qt with GIF support turned on. See "configure -help" for details.
J-P Nurmi
I never am able to do this:
I did what the previous poster said,
[qtcode]
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *pushButton = new QPushButton(QIcon("TestQT.ico"), "text", 0);
pushButton->show();
return app.exec();
}
[/qtcode]
However, even though TestQT.ico and this program are in same folder, it does not work... neither does C:/blabla.... What do I do?
ICO is neither a supported format. It is available as a commercial solution, though. As far as I remember, there is some open source implementation out there as well.
You can simply use supported image formats, like PNG for constructing a QIcon.
Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.
J-P Nurmi
Bookmarks