Background image or transparency from Style Sheet does not show on QWidget
-
Hi Rahul, thanks for your answer.
The ":" means the file is registered in resources RCC file. In this case it isn't registered so the relative path to the file is given instead, and that must be done without ":". -
-
What OS are you on? If windows is your target, then "this qt labs article ":http://labs.qt.nokia.com/2009/09/15/using-blur-behind-on-windows/ could interest you.
-
PS: I have partly found an answer regarding the background image.
Changing adding a preceding dot to the path seems to help locating the file:
@QToolBar {background-image: url(./wood.jpg)}@However, the same applied to the MainWindow does not work:
@MainWindow {background-image: url(./wood.jpg)}@ -
@Eddy: Target is Linux in general, I am working on Ubuntu + Gnome at the moment.
[quote author="Eddy" date="1314551129"]What OS are you on? If windows is your target, then "this qt labs article ":http://labs.qt.nokia.com/2009/09/15/using-blur-behind-on-windows/ could interest you.[/quote]
-
Rahul: I am working with Python, and I believe the "build" directory is something of C (?). Anyway, as stated later, using "./wood.jpg" as a path pointed to the file in the same directory.
As to set the window transparent, I have tried:
@self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)@
But that make the entire main widget transparent, and it is not the desired result: I wan the partial opacity of the main widget to remain, and the black background it is painted on to be fully transparent.[quote author="Rahul Das" date="1314551126"]If you are using relative path, make sure you have the image , relative to the deploy/ build directory.
In this case, copying the wood.jpg to your build dir solves the problem.
Edit : You can set the opacity of the window, to make it transparent :)[/quote]
-
Copying the image to the build directory and setting the style sheet as @background-image: url(./Jellyfish.jpg);@ worked for me.
And "opacity":http://doc.qt.nokia.com/latest/qwidget.html#windowOpacity-prop as well!
and sorry , am not familiar with Python :(
-
As stated above "./wood.jpg" worked indeed (with the file placed in the same directory as the source file). But why that does not work for the MainWindow() i don't know :(
As to setting opacity, it worked indeed, but on all widgets, whereas I want the main widget only to be translucent and not its children.
[quote author="Rahul Das" date="1314551605"]Copying the image to the build directory and setting the style sheet as @background-image: url(./Jellyfish.jpg);@ worked for me.
And "opacity":http://doc.qt.nokia.com/latest/qwidget.html#windowOpacity-prop as well!
and sorry , am not familiar with Python :([/quote]
-
Rahul, thanks again.
Perhaps it is easier if I show what I would like to achieve, see this mockup:
To achieve this, I have to change the background of the main widget to show the wood texture. That didn't work so far. I am not working with a QMainWindow() however, so there is no central widget I believe. The main window of my application inherits from a QWidget().
The alternative is to make the main widget completely transparent, which I achieved with setting property: @self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)@
I would also try to make the background semi-transparent, using an alpha value of eg. 50% in the style sheet: which does not work so far.
-
Update:
Using a tip from "another post":http://www.qtforum.org/article/23474/background-image-for-qwidget.html#post86564, I've added the following to my code:
@self.palette = QtGui.QPalette()
self.palette.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QImage("./wood.jpg")))
self.setPalette(self.palette)@It worked, so it means it is possible. Now I need to do the same using a style sheet, please let me know if you have an idea how to make this happen.
Thanks.
-
Update:
On "StackOverflow":http://stackoverflow.com/questions/4830517/qt-stylesheet-background-color-yes-background-image-no it is porposed to derive the MainWidget from QFrame() instead of QWidget() and setting the background image does work then.
This problem is "recurrent":http://developer.qt.nokia.com/forums/viewthread/4713. But there's no clear solution to be seen anywhere except for the above.
Any thoughts?Cheers.