[Qt-interest] background pixmap of a QFrame

Girish Ramakrishnan girish at forwardbias.in
Wed Apr 22 07:37:06 CEST 2009


Ramakrishnan Muthukrishnan wrote:
> Hi,
> 
> I am new to Qt and also have never done GUI programs before, but have
> been enjoying my journey so far.
> 
> I had been modifying some Qt3 programs to work with Qt4. I had a piece
> of code like this in Qt3:
> 
>     ctlFrame = new QFrame (this);
> 
>     QPixmap *a_pix = new QPixmap( a_xpm );
>     sFrame = new QFrame( ctlFrame );
>     sFrame->setPaletteBackgroundPixmap( *a_pix );
> 
> I modified this for Qt4 as
> 
>     spalette.setBrush(QPalette::Background, QBrush(a_pix));
>     sFrame->setPalette(spalette);
> 
> as specified in the Qt4 porting document and the Qt3 support classes
> reference. But I don't see the background pixmap at all. I am able to
> setPixmap over labels. But backgroundpixmaps for QFrames do not seem
> to show up. What could be the reason?
> 

You will also need,
sFrame->autoFillBackground(true);

Also, QPalette::Background is renamed to QPalette::Window. Please report
a doc bug to trolltech.

If you have the path to the image, easier way is just use a stylesheet
(it also allows you more control over the background image like
repetitions).

    sFrame->setStyleSheet("background-image: url(whatever.png)");

Girish



More information about the Qt-interest-old mailing list