oswalidos
15th April 2012, 23:09
Hello,
I'm using qt creator 2.4.1, Qt 4.8 on Ubuntu 10.10.
I need to make a background image resizable for a Qwidget, for the main QWidget i override resizeEvent in the generated file(widget.cpp) and it works fine, now i want to put inside my main QWidget another QWidget and give it a resizable background image as well so i found out the promoting to buid my custom widget (ZoneSup is just a QWidget where i override resizeEvent) .
my custom widget :
#ifndef ZONESUP_H
#define ZONESUP_H
#include <QFrame>
#include <QDebug>
#include <QResizeEvent>
#include <QPixmap>
#include <QPalette>
class ZoneSup : public QWidget
{
Q_OBJECT
public:
ZoneSup(QWidget *parent = 0);
protected:
void resizeEvent(QResizeEvent *); // virtual};
};
#endif // ZONESUP_H
#include "zonesup.h"
ZoneSup::ZoneSup(QWidget *parent) : QWidget(parent){
}
void ZoneSup::resizeEvent ( QResizeEvent * event )
{
qDebug() << "ZoneSup::resizeEvent " << event->size().width() << " ," << event->size().height();
QPalette palet = palette();
QPixmap backGroundPicture(":/image/bg1.jpg");
QPixmap pixmapBackGround(backGroundPicture.scaled(event->size()));
palet.setBrush(QPalette::Background, pixmapBackGround);
setPalette(palet);
}
resizevent is called but the background image is not shown.
the same code used for the main QWidget works fine.
I have no error and no warning.
Thanks in advance
I'm using qt creator 2.4.1, Qt 4.8 on Ubuntu 10.10.
I need to make a background image resizable for a Qwidget, for the main QWidget i override resizeEvent in the generated file(widget.cpp) and it works fine, now i want to put inside my main QWidget another QWidget and give it a resizable background image as well so i found out the promoting to buid my custom widget (ZoneSup is just a QWidget where i override resizeEvent) .
my custom widget :
#ifndef ZONESUP_H
#define ZONESUP_H
#include <QFrame>
#include <QDebug>
#include <QResizeEvent>
#include <QPixmap>
#include <QPalette>
class ZoneSup : public QWidget
{
Q_OBJECT
public:
ZoneSup(QWidget *parent = 0);
protected:
void resizeEvent(QResizeEvent *); // virtual};
};
#endif // ZONESUP_H
#include "zonesup.h"
ZoneSup::ZoneSup(QWidget *parent) : QWidget(parent){
}
void ZoneSup::resizeEvent ( QResizeEvent * event )
{
qDebug() << "ZoneSup::resizeEvent " << event->size().width() << " ," << event->size().height();
QPalette palet = palette();
QPixmap backGroundPicture(":/image/bg1.jpg");
QPixmap pixmapBackGround(backGroundPicture.scaled(event->size()));
palet.setBrush(QPalette::Background, pixmapBackGround);
setPalette(palet);
}
resizevent is called but the background image is not shown.
the same code used for the main QWidget works fine.
I have no error and no warning.
Thanks in advance