PDA

View Full Version : Problem displaying image on a customized button



bhavikdhoot
16th December 2010, 05:33
We are migrating from Qt3 to Qt4. In Qt3, we were using “QButton” as the base class from which we have derived and created our own class “QCButton” to create a customized button with text and image upon it. We used a label whose parent will be the QCButton’s object to set an image on it and with the help of setPaletteBackgroundPixmap() function we were able to set an image and create a customized ellipse-shaped button.

class QCButton : public QButton
{
...
};

In Qt4, we have used QAbstractButton as the base class (since QButton is obsolete) from which we have derived and created our own class “QCButton”.

class QCButton : public QAbstractButton
{
...
};


We have used the below statements as an alternative to the setPaletteBackgroundPixmap():-

QPalette palette;
palette.setBrush(label->backgroundRole(), QBrush (pixmap));
label->setPalette(palette);

But, using this we are not able to achieve what we want in Qt4 i.e. a customized ellipse-shaped button with a text on it.

Please advice Qt Experts.
Thanks in Advance!
-- Bhavik.

bhavikdhoot
16th December 2010, 11:48
Ok guys! Got the solution...Basically, in this case we have to reimplement the paintEvent() method. This has become a must in Qt4 since it is a pure virtual function, which was not the case in Qt3.