I have made a QMessageBox in the following way:
msgBox.setText("Are you sure?");
msgBox.setStandardButtons(QMessageBox::Yes| QMessageBox::No);
msgBox.setStyleSheet("background-image: url(image)");
msgBox.exec();
Unfortunately using setStyleSheet on the messagebox sets the background for the buttons, the textbox and the actual msgbox. This is not wat I want. I want only the msgbox to have a background not the other components of the messagebox. I found out that using:
msgBox.button(QMessageBox::Yes)->setStyleSheet(...)
can be used to set the background on just the buttons. Is there a command with which I can set just the background of the msgBox, without adding a background to the buttons and the textbox?
You can limit to which elements the style will be applied by using a selector. So to only apply the style to the QMessageBox itself and not its children, you would use:
msgBox.setStyleSheet("QMessageBox { background-image: url(image) }");
For more details, see The Style Sheet Syntax - Selector Types.
Related
I have a JavaFX button that has been set as Default Button so the user can select it with the Enter key. Currently, it has a blue background:
But I'd like to make it look like a normal button:
I took a look at the JavaFX CSS Guide and it looks like there's only one feature to override (-fx-base).
But changing this feature has unpredictable effects—sometimes it eliminates the button's gradient; sometimes it makes the button transparent.
Is there a simple way to just get rid of the Default Button styling?
My guess is that you are looking in the wrong style sheet. The old default style sheet caspian.css was replaced with modena.css. So setting default value for -fx-base from modena.css should fix the issue:
.button:default {
-fx-base: #ececec;
}
I want to cusomize QToolButton class so it won't show arrow subcontrol when button has a context menu. But I need to apply this style sheet only for buttons with QToolButton::MenuButtonPopup popup mode. How to do it properly? I have tried the following sheet:
QToolButton[popupMode != "1"]::menu-indicator {image: none}
but it doesn't work.
This solution what worked for me. I used a dynamic Property (bool) in the Designer to convert a Check Box into an Indicator Lamp.
QCheckBox[indicator=true]::indicator::checked { image: url(:themes_22x22/Icons_oxygen22x22/emblems/emblem-important.png);}
QCheckBox[indicator=true]::indicator::unchecked { image: url(:themes_22x22/Icons_oxygen22x22/status/user-online.png);}
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 an editable combo box on the input form, which background must change when it receives focus. The following code works perfect for QLineEdit but has no effect on QComboBox.
QLineEdit, QComboBox { background-color: green; }
QLineEdit:focus, QComboBox:focus { background-color: red; }
Is it possible to make QComboBox behaves as expected like QLineEdit using only Qt style sheets?
You may need to do this by subclassing QLineEdit, and installing it into the combo box (with QComboBox::setLineEdit()). Then, override the focusIn() and focusOut() functions of QLineEdit, and set a style sheet with the appropriate background color in those functions.
Another way would be to install an event handler on the combo box, (and/or its associated QLineEdit) and trap focus in/out events, and change the style sheet then.
I am using stylesheets. I want to set style information for the main message text and the informative text for a QMessageBox. Is it possible to access these sub-controls ?
Yes it is possible. The trick is to know how to select the sub-controls. Here's how you can change the style of the text, in this example I make the dialog grey and the text off-white:
QMessageBox {
background-color: #333333;
}
QMessageBox QLabel {
color: #aaa;
}
The second clause uses a Descendant Selector which in this case means "any QLabel that is a descendant of a QMessageBox including children and grandchildren etc". You can be more specific and only select children with QMessageBox > QLabel
I found this information here http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html
Just use rich text - with the exception for the detailed text since it's always interpreted as plain text.
Take a look at the documentation here.
You can simply do QMessageBox {font:...} in the stylesheet or with setStyleSheet(...)
Unless you trying to set the style for the main message text separately from the informative text... is that what you are trying to do?