You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

im_reev

Beginner

  • "im_reev" is male
  • "im_reev" started this thread

Posts: 9

Location: India

Occupation: Software Engineer

  • Send private message

1

Friday, April 3rd 2009, 10:25am

image on pushbutton on Qt4.4.3

Hi friends,
It will be very helpful if anyone can provide an solution to my query.
I am working on redhat enterprise 4 version.
I have developed an application on Qt3.3.4.
I have used image on the pushbutton background in that application.
sample code:
QPushButton *pb = new QPushButton(this, "MyButton");
QImage img;
if(img.load(IMG_PATH"pb_bg.png"))
{ pb->setBackgroundPixmap(img); }
else
{
// set back ground and foreground color for button. }
This code is working fine for Qt 3.3.4
But when i port this application on Qt 4.4.3 than it is not displaying the image.

Sample code:

QPushButton *pb = new
QPushButton(this, "MyButton");
QImage img;
QPixmap pix;
if(img.load(IMG_PATH"pb_bg.png"))
{
pix = QPixmap::fromImage (img);
pb->setPaletteBackgroundPixmap(pix);
}
else
{
// set back ground and foreground color for button. }

On the execution of above code snippet, it gives a black background on the button as an image.
One more thing i can not use QPushButton::setIcon API as i need text over the image.
that is image on the pushbutton should apear as an overlay.
I found out one strange thing that the API "setPaletteBackgroundPixmap()" is working fine for QDialog but for pushbutton.

Thanks a lot in advance.
Reev--
A bug in debugger's heart. 8o ?( :rolleyes: 8| ?( :wacko:

Every step you take, brings your destination near or far. :S
Depends whether you are going in same direction or opposite. 8)

thec0der

Beginner

  • "thec0der" is male

Posts: 39

Location: Bulgaria

  • Send private message

2

Friday, April 3rd 2009, 11:48am

I use StyleSheet for such thing.
In your case:

Source code

1
2
3
....
pb->setStyleSheet("background-image: url(your_img.ext);");
....

im_reev

Beginner

  • "im_reev" is male
  • "im_reev" started this thread

Posts: 9

Location: India

Occupation: Software Engineer

  • Send private message

3

Friday, April 3rd 2009, 12:21pm

Thanks a lot, Buddy!!
It works perfectly.


Besties,
Reev

:thumbsup: 8o
Every step you take, brings your destination near or far. :S
Depends whether you are going in same direction or opposite. 8)