Solved Why all styles are not applied to promoted widget ??
-
I have some ui files. I have promoted "forum.h" in mainWindows.h. The portion of forum.h doesn't contain all stylesheets which are actually in it.
Like
forum.ui has border-image:url(:/Resources/images/background.jpg);
, also it has widget with color of rgba(20,30,10,0.5);
and it has another label with border-image:url(:/Resources/images/logo.png);These all things are shown in forum.ui in Qt Creator
BUT,
in promoted widget the background of label is working and others are not working
Does Qt support Jpg file or What is the reason behind it?? -
I got the right answers.
Here are some points to be considered while applying stylesheets in QT
- If you know css then
rgb(10,20,30,0.8) works but in QT it doesn't
use rgba(10,20,30,0.8) instead.
Never apply major style sheets like border image in widget name (Suppose the file name is "login.ui" don't apply style sheets in login object)
It may or may not work for all files.
But it worked for me.Thank You
- If you know css then
-
@Thank-You Take a look at generated ui_forum.h (build first your project).
See https://doc.qt.io/qt-5/designer-using-a-ui-file.html -
@jsulm I have generated these files using QT Creator. I used drag and drop method to build ui. I have promoted widgets to another using the same method.
I created new ui form using Designer Form Class using CTRL + N
Either I didn't understand what are you saying
Or You did not understand my Question.The main problem is all of stylesheets are not working. Only some stylesheets are working.
i hope you understand this Question @jsulm
-
I got the right answers.
Here are some points to be considered while applying stylesheets in QT
- If you know css then
rgb(10,20,30,0.8) works but in QT it doesn't
use rgba(10,20,30,0.8) instead.
Never apply major style sheets like border image in widget name (Suppose the file name is "login.ui" don't apply style sheets in login object)
It may or may not work for all files.
But it worked for me.Thank You
- If you know css then
-
You wrote
rgba(x,x,x,x)
in your inital post... Still dont know what the issue was about, but if it's working now, it's fine :)Qt Stylesheet can use
rgb(r,g,b)
as well asrgba(r,g,b,a)
with additional alpha value. Of course you can't pass 4 values torgb()
.https://doc.qt.io/qt-5/stylesheet-reference.html#list-of-property-types
-
@Pl45m4 Sorry rgba() was mistake in initial post.
But we can use 4 values in rgb() like rgb(x,x,x,x) in CSS
So I mean to say that if you have to use alpha value then use rgba() instead of just rgb()
Thank You -
It's just the naming of the function. Since Qt has an extra function for alpha values,
rgb
is for r, g, b only.
If you know it, there is nothing special about it. And one can read the documention, to see how it works:)