Problems setting a background image
Hi to all,
I have some problems setting a background image on a QWidget.
I tried with the designer and also with code so:
Code:
ImageRenderer
::ImageRenderer(QWidget* parent
) m_qImage(NULL)
{
setFixedSize
( QSize(640,
480) );
setStyleSheet("background-image: url(:/resources/images/logo.jpg);");
//m_image = new QPixmap();
m_qImageBuffer = (uchar *)malloc(640 * 480 * sizeof(uchar));
}
The image is correctly in the resouces.
Where am I wrong?
Regards
Re: Problems setting a background image
Sure you have the uri right? what is the output of
Code:
QPixmap p
(":/resources/images/logo.jpg");
qWarning() << p.isNull();
Or you don't have loaded the jpeg support. Try to set a png image for testing.
Re: Problems setting a background image
Did you reimplement the paint event for your widget? Does the class contain Q_OBJECT macro?
Re: Problems setting a background image
it returns true but is really strange, the image is there
Quote:
Originally Posted by
wysota
Did you reimplement the paint event for your widget? Does the class contain Q_OBJECT macro?
Hi Wysota yes this is the class:
Code:
class ImageRenderer
: public QWidget{
Q_OBJECT
public:
~ImageRenderer();
void setImage(IplImage*);
public slots:
QImage IplImageToQImage
(const IplImage
* iplImage
);
protected:
/* paint event */
private:
IplImage* m_frame;
/* OpenCV -> Qt */
unsigned char* m_qImageBuffer;
};
#endif //#ifndef _IMAGERENDERER_H_
Quote:
Originally Posted by
Lykurg
Sure you have the uri right? what is the output of
Code:
QPixmap p
(":/resources/images/logo.jpg");
qWarning() << p.isNull();
Or you don't have loaded the jpeg support. Try to set a png image for testing.
I also converted to png and nothing
Re: Problems setting a background image
Quote:
Originally Posted by
franco.amato
it returns true
Well that's bad and means you havn't the right path or not installed the jpeg image plugin. How does your qrc look like and further how do you implement the paint event function?
Re: Problems setting a background image
So how did you implement paintEvent?
Re: Problems setting a background image
Quote:
Originally Posted by
wysota
So how did you implement paintEvent?
At the moment the paintEvent is empty it should contains something using the stylesheet in the ctor?
Re: Problems setting a background image
If it is empty then whatever you do (even if you get jpgs to work as Lykurg pointed out) your background won't appear.
Re: Problems setting a background image
Quote:
Originally Posted by
wysota
If it is empty then whatever you do (even if you get jpgs to work as Lykurg pointed out) your background won't appear.
I converted the image in png and the url is correct, now it find the correct url but I still don't see the background.
So what I have to write in the paintEvent?
Added after 6 minutes:
Quote:
Originally Posted by
wysota
If it is empty then whatever you do (even if you get jpgs to work as Lykurg pointed out) your background won't appear.
I changed the paintEvent so:
Code:
{
p.
setRenderHint( QPainter::Antialiasing,
true );
// image
p.drawPixmap( 0, 0, m_pixmap );
}
and the ctor so:
Code:
ImageRenderer
::ImageRenderer(QWidget* parent
) m_qImage(NULL)
{
setFixedSize
( QSize(640,
480) );
m_pixmap.load(":/CertiIris/images/logo.png");
}
and now I can see the background image.
So my question is: where I can use styleSheet and where not?
Regards
Re: Problems setting a background image
If you override the paint event and do custom painting then how do you expect to get stylesheets to work if they are part of the original painting routine?
A description of what is needed for a bare QWidget to respect stylesheets was recently provided on the forum. Search for it if you want.
Re: Problems setting a background image
Quote:
Originally Posted by
wysota
If you override the paint event and do custom painting then how do you expect to get stylesheets to work if they are part of the original painting routine?
A description of what is needed for a bare QWidget to respect stylesheets was recently provided on the forum. Search for it if you want.
Ok thank you