Limiting the effects of a stylesheet to the parent widget? - css

I am setting the background color of a QWidget subclass. When I do this using a stylesheet, the styles of the other components in the QWidget change (eg, the color of a PushButton, and its look changes).
How do I make sure only the background color of the container widget changes and the rest of the child components remain unchanged?

One way is to specify an ID selector. Make sure to set the objectName of your container widget (with setObjectName()) and use that name in the CSS selector. Assuming a widget named MyContainer, you would use something like this:
QWidget#MyContainer {...}

Try !imporant qualifier on child els background color property.

Related

Qt:Unable to set Background color for qComboBox properly

I have a QCombobox and I want to set a white background color.This is my code.
QComboBox *cBox = new QComboBox;
cBox->addItem("Text1");
cBox->setStyleSheet("background-color:white");
This combobox has a parent widget whose background is an image and is set as given below:
ui->centralWidget->setStyleSheet("border-image:url(./image.png)");
When I set the parent Widget[centralWidget] background as some other color,then the white BG works properly for the combobox.But when I set an image as the parent Widget background,the UI looks like this.
In the above pic,the black Bg is an image.Could someone highlight me what am I missing.Any help will be really helpful.
When you do not indicate to which widget you are going to apply some property, they will be applied to all your children, for this reason the same QComboBox background image is applied to the child of centralWidget.
In your case you want to apply only to the centralWidget, and by default Qt Designer uses the same name for the name of the variable that represents the widget and the objectName.
So if you want to apply to a widget we can use the objectName as selector:
QWidget#centralWidget{ border-image:url(./image.png)}

PyQt4: restrict stylesheet to parent

So, first off, I've already read this, and everything I can find online says the same thing. To restrict the scope of a stylesheet setting do this:
self.setObjectName( self._TAG )
self.setStyleSheet( "#{} {{ background-color:{}; }}".format( self._TAG, "#d5d5d5" ) )
Where self is an object derived from QFrame. The problem is that, at least in the case of objects derived from QFrame, it only excludes children that don't descend from QFrame. The buttons and checkboxes retain the default color, but the QLabels inherit from the parent.
So is there any way around this, other than explicitly specifying the stylesheet for each child?
You have to set the autoFillBackground property of the Qlabel to True, otherwise, the label won't paint its background:
myqlabel.setAutoFillBackground(True)

Change BorderContainer background color with AS - Flex 4

I'm trying to change the background color and or text color of a BorderContainer in flex 4 using Action Script, but have not idea how to.
The Border Container component doesn't seem to have any properties like:
idname.color = "#333333";
idname.backgroundcolor = "#333333";
How might I go about doing this?
thanks!
You can set styles (which are different from properties) in ActionScript like so:
idname.setStyle("backgroundColor", 0xff0000);
Not sure if this is the only way to do it, but by creating a css style your able to change the background, text color, and other style attributes and call the style's name in Action Script.
idname.styleName = "css-stylename";

Is there a css attribute to specify a background color for a LinkButton's up state?

There are styles for over and clicked but no up state.
Is it possible?
You can use the upSkin style or the skin style to define the background of a button
So, instead of referencing the downSkin, or overSkin, or disabledSkin, you would just reference 'skin' or upSkin.
I believe you'll need an actual skin, and not an image to accomplish this, though.
http://www.adobe.com/devnet/flex/articles/skins_styles.html

QT Transparent Layout

I am using a vertical layout (QVBoxLayout) to manage buttons. I would like to make its background color as 50% black transparent. Is it possible ?
sw
Depending where you want the border of the transparent area, you will need to group the buttons in a widget (as SigTerm said) and then you can assign a color either via the palette
QPalette palette = widget->palette();
palette.setColor(QPalette::Window, QColor(100,100,100,100));
widget->setPalette(palette);
or use a stylesheet
widget->setStylesheet("QWidget{background-color: rgba(100,100,100,100);}";
the stylesheet has the advantage that you can style all of your application from one spot that is not in the code and set an application wide stylesheet via QApplication::setStylesheet(QString)
Ahem... it's been a while since I used Qt, but as far as I know, QVBoxLayout has no background color, so no, it isn't possible. Layout isn't a widget and it isn't being painted at all, it only manages child widget sizes.
If you want to create colored layout, you'll probably have to create a widget with whatever color your want, and then parent QVBoxLayout to that widget.
It'll become more fun if you want color of all layout's children to be affected by color of QVBoxLayout's parent, but I think that "Embedded Dialogs" demo from Qt4 demo may give you an idea about how it can be done.

Resources