PDA

View Full Version : Qt5/C++ - QComboBox - change currrent text color and the dropdown text colour



jimbo
19th July 2016, 13:40
Qt Creator 3.6.1 - Based on Qt 5.6.0 (MSVC 2013, 32 bit) - Windows 10

Hello,


qApp->setStyleSheet("QGroupBox, QComboBox, QRadioButton, QPushButton, QLabel, QLineEdit"
"{ color: blue }"); // text colour

ui->myComboBox->setStyleSheet("QListView { color: blue; }");
ui->myComboBox->setStyleSheet("QComboBox { background-color: white }");
I'm trying to set the text colour and the dropdown list text colour on a QComboBox.
I tried changing the order and it seems that the last setStyleSheet is the one that takes effect.
How do I apply both to the QComboBox?

Regards

anda_skoa
19th July 2016, 13:44
The last two are obviously exclusive, since the stylesheet in line 5 overwrites the one set in line 4.

Are you saying that the rule set in line 1 and the rule set in line 5 are not both active?

Cheers,
_

jimbo
19th July 2016, 14:06
Hello anda_skoa,

Thanks for your reply,


The last two are obviously exclusiveI gathered that from my test.

I can get lines 1 & 5 working.
I can get lines 1 & 4 working.

What I would like to is get line 1 and lines 4 & 5 working together.
I can't work out the syntax required.

Regards

anda_skoa
19th July 2016, 17:18
You need to combine the two strings into one.

Two calls to a setter function will always result in the second value being the current value.

Cheers,
_

jimbo
19th July 2016, 19:10
Hello,

Many thanks, this seems to work.


ui->myComboBox->setStyleSheet("QComboBox { background-color: white }" "QListView { color: blue; }");Regards