Re: Push Button with image?
Try with a png file and with an absolute file path. If it works then either you are missing an image plugin for jpeg in the environment where you run the application or the file you are trying to load can't be found or accessed.
Re: Push Button with image?
THANK YOU!!
Using the complete path worked!
Re: Push Button with image?
If you want to use the resource system, is it not that there is a ":/" missing? In my application I use resiurce files like this:
QFile qfi(":/texts/res/usageNotes.txt");
This works:
Code:
if(qpm.load(":/img/myImage.jpg"))
{
icon.addPixmap(qpm);
ui->pushButton->setIcon(icon);
}
else ui->label->setText("nincs betöltve");
Otherwise I have the guess that the absolute path works because the executable file is not generated in the same directory as the code, so the executable file whilst working is trying to find the image on the relative path from itself, where is actually nothing, as there might be even no directory like that.
Re: Push Button with image?
Simplest way to set image on the Push Button::
btn = (QPushButton *)ui->btn;
btn->setIconSize((QSize(56,68)));
QPixmap* pixmap1 = new QPixmap(":/images/orange.bmp");
QIcon icon1(*pixmap1);
btn->setIcon(icon1);
I think this might help you..
Re: Push Button with image?
Why this cast ? (which is an old C-style cast anyway).
Re: Push Button with image?
Anyway its works fine. Finding the simplest way to use yet more powerful
Re: Push Button with image?
ui->btn->setIconSize((QSize(56,68))); isn't work?
and in qt don't use old c-style cast. you have static_cast and object_cast
Re: Push Button with image?
You shouldn't need any casts here. Be it implicit or explicit, C or C++ style.
Re: Push Button with image?
btn = (QPushButton *)ui->btn;
btn->setIconSize((QSize(56,68)));
Re: Push Button with image?
Quote:
Originally Posted by
Gokulnathvc
btn = (QPushButton *)ui->btn;
btn->setIconSize((QSize(56,68)));
But why the cast? Not that this is relevant to the subject (it was about a missing file) but since we're already here, let's solve this situation too.