Qt Stylesheet for QMessageBox - qt

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?

Related

Qt - How to change background from editable QComboBox?

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;}");

Elide/text-overflow/ellipses text in Webkit

It is possible to configure the QWebView to work with "Elide" disabled (equivalent to Qt::ElideNone)?
The "Elide" graphic texts being compressed (elieded) to fit inside the select.
Example:
I wish the entire text to be displayed when clicked on comobox (selectbox). Is it possible?
Thanks.
[edit]
I think it may be the way the styleSheet (qt):
QComboBox QAbstractItemView {
...
}
I just do not know which property to use styleSheet disable "elited".
Maybe something like this:
QComboBox QAbstractItemView {
elided: none;
...or...
elide: none;
}
Anyone know a link with all properties stylesheets used in QT (I searched but did not find)?
[edit 2]
I tried white-space: pre; and white-space: nowrap; that seems the most logical, but does not work with QAbstractItemView, will be the selector is another?
You can change the textElideMode property by adding a rule QComboBox QAbstractItemView { qproperty-textElideMode: ElideNone } (See Style Sheet Syntax - Setting QObject properties) but it will only clip the text on the right without extending the drop-down box.
According to the code source, the list view adjust its size to its content when it is displayed as a popup which is done by adding this in the stylesheet:
QComboBox {
combobox-popup: true;
// To make room for the possible scrollbar
// (the value has to match the scrollbar width of the current style/platform)
padding-right: 20px;
}
Outside that popup mode, the width of the drop-down box is taken from the list view minimum size (or from the min-width css property of the QAbstractItemView), but there doesn't seem to be a way, with css only, to automatically adjust the size of the drop-down box to the content of the list.

QComboBox:focus Qt Style Sheet

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.

How can I set the stylesheet of a certain element of Qmessagebox

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.

How can I make a Qt widget ignore style sheets set on parent widgets?

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.

Resources