How to properly set a background image of a custom widget
Hi forum,
I have a custom widget, showing the output of a video camera ( after some calculations ) and I would display a background png image.
I tried with the
Code:
myWidget->setStyleSheet("background-image: url(:/screen.png);");
with no results.
Should i set it manually in the paint event?
Regards
Re: How to properly set a background image of a custom widget
Quote:
Should i set it manually in the paint event?
Is the path to the resource correct? (You can test by trying to load in code: QImage::load()).
You can try drawing it in the paint event (using QPainter::drawImage()). Don't load the image in the paintEvent(), load it in your widget constructor and store it as a member variable.
Of course, if your video frame is the same size as the window, setting the background image won't have any effect because the video frame will overwrite it.
Re: How to properly set a background image of a custom widget
Hi,
yes the path is correct.
I would like to display the bg image only while I am not receiving frames from the camera.
Thanx
Re: How to properly set a background image of a custom widget
Quote:
I would like to display the bg image only while I am not receiving frames from the camera.
The I think the only way to do that is to paint it manually in the paintEvent(). The stylesheet doesn't know anything about your application's details, so your paint event has to decide whether to show the background image or the current frame.