Before changing:
After changing parent widget styleSheet property to this:
background-color: rgb(5, 34, 78);
I see this:
QComboBox become really different. What happens? How to use regular QComboBox on dark background?
I am using Qt 5.5 without QML.
You have to set it to the main window only
yourWindow->setStyleSheet("{background-color: #HexNumber}");
or tell the QComboBox to not have style:
yourWindow->setStyleSheet("QComboBox{background-color:none}");
or
yourWindow->setStyleSheet("QComboBox#ComboName{background-color:none}");
According to manual:
When a style sheet is active, the QStyle returned by QWidget::style()
is a wrapper "style sheet" style, not the platform-specific style. The
wrapper style ensures that any active style sheet is respected and
otherwise forwards the drawing operations to the underlying,
platform-specific style (e.g., QWindowsXPStyle on Windows XP).
If all you want is to change some colors, leaving selected style unchanged, the better solution would be to use QPalette.
Related
I'm facing this problem when styling an editable QComboBox:
I'm unable to change the color of the grey box inside the QComboBox...
Any idea how to change it just with a stylesheet?
Thank you
What about
QComboBox:editable {
background: white;
}
? I did not test it, but the reference seems good to me.
Edit
As of using Qt version 5.6.2 the provided change works as desired. No differently colored box inside the currently edited QComboBox.
This shoud work
YourCombobox->findChild<QLineEdit*>()->setStyleSheet("QLineEdit {background: green;}");
Previous line get the reference to the QLineEdit which is part of the QComboBox widget and applies the style sheet to it, not to the combobox.
I don't know if this could also work, if you want to try it and give a feedback..
YourCombobox->setStyleSheet("QLineEdit {background: green;}");
Simply put, I have a JavaFX Textfield that I wish to 1) change the text color on, and 2) change it back to that specified in CSS. Does anyone know how to (generally) access css colors etc. from within the JavaFX code?
AnyFxElement.setStyle(String elementCss);
For source of all the css capabilities I reccomend looking up caspian css.
To remove a style use the code:
// remove the background color on the button
yourElement.setStyle(null);
To set it back to it's default style:
// set the button style back to the default class
yourElement.setStyle(".yourStyle");
I have a Flex Spark Button that I've changed the background to a dark color using
s|Button {
color: #66ffff;
chromeColor: #333333;
}
The problem is that when the button is disabled, it's very hard to read (the text color and background color are very close). I've tried setting the disabled color to something lighter
s|Button:disabled {
color: #ffffff;
}
But the disabled text's color is not #ffffff. It's some combination of the text color and the background. Is there someway to disable this behavior (ie, specify the exact disabled state's text color)?
You are battling with the default skin of the button. If you were to create a new button skin based on ButtonSkin, you would see that the alpha for the entire skin is set: alpha.disabled="0.5".
Setting the value to 1.0 solves your problem, but it seems overkill to define this entire skin just to modify this single value.
Hopefully, there is a more elegant way. I tried setting alpha: 1.0; in the disabled style, but it doesn't take. The only thing I have been able to do is create a new button style, set alpha.disabled="1.0" and telling the button to use that slightly modified style.
You can create 2 .css files, one for the standard view and one for the "disabled" view and set your own button properties. Write a function which changes the .css file to use.
When adding a QComboBox control in Qt Designer, I get a terrible looking, non-native control:
On digging further, it turns out that two of the parent controls, QParentWindow and QStackedWidget, have style sheets that QComboBox is inheriting. If I delete the custom styles, then I get a native QComboBox like the one on the left.
How can I have QComboBox (and widgets generally) NOT inherit parent styles? Or, how can I create a style for, say, QParentWindow, and do it so that it's local only and does not cascade?
I don't think you can prevent it from cascading. But by using more specific selectors in your stylesheet, maybe you could define properties only for your QParentWindow class or specific object.
you need to define a style and then assign it to that object:
QString settingStyle = " QGroupBox#groupBoxSettings {\
background-color: rgb(248,248,248);\
border: 1px solid rgb(170, 170, 255);\
border-radius: 3px;\
border-color:rgb(170, 170, 255);\
}";
ui->groupBoxSettings->setStyleSheet(settingStyle);
here "groupBoxSettings" is the object name. This way any thing inside the groupbox they'll have their own style.
I have a class that inherits QStandardItem and I put the elements in a QTreeWidget. The class receives notifications from the outside and I want to change the background color of the item based on what happened.
If I do not use stylesheets, it works just fine, like this:
void myClass::onExternalEvent()
{
setBackground(0, QColor(255,0,0)));
}
However, as soon as I put a stylesheet on the QTreeWidget, this has no effect : the stylesheet seems to override the setBackground() call.
So I tried :
void myClass::onExternalEvent()
{
this->setStyleSheet("background-color: red");
}
but this is probably all wrong, it changed the color of some other element on my screen, not sure why.
Does anyone have an idea on how I can alter the background color like with setBackgroundColor but still be able to use stylesheet on my QTreeWidget?
Palettes propagate to the children of a widget, and it's bad to mix and match style-sheet controls and native controls (I do not have a citation for the latter handy, but I have read it in the QT docs somewhere).
That being said, try setting setAutoFillBackground(false) on your QStandardItem derived class.
EDIT: Sorry - also, are you specifying the QTreeWidget in the stylesheet or just setting "background-color:"? If you specify the QTreeWidget only in the stylesheet that might take care of it as well.
QTreeWidget { background-color: white; }
But I think you still have to set the autoFillBackground(false).