You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, July 24th 2005, 3:00am

[qt4] Change disabled QLineEdit's background/foreground colours?

I am using the plastique theme under windows, but I don't like the way disabled QLineEdit's have a white background. I would also like to change the colour of the text that is displayed in the QLineEdit.

How can I achieve this? In Qt 3 it could be done via the designer, but the option is not available in Qt 4.

I think I have to start subclassing things, but I know nothing about this topic. Can anybody provide a simple example of what I have to do.

Many thanks,
Royce

bhobbs

Beginner

  • "bhobbs" is female

Posts: 15

Location: Lincoln, NE

Occupation: engineering intern at EFJohnson

  • Send private message

2

Wednesday, August 17th 2005, 10:19pm

I did something similar with the color of a checkbox. Here's the code that I wrote to make the text displayed in the disabled checkbox the same as the enabled checkbox:

Source code

1
2
3
4
5
6
7
8
9
QDialog* displayDetailsDialog = new QDialog(this);
	Ui::DisplayDetailsDialogDesign dialogUI;
	dialogUI.setupUi(displayDetailsDialog);
	QPalette newPalette(dialogUI.ClearedCheckBox->palette());
	newPalette.setColor(QPalette::Disabled, 
                        QPalette::Foreground, 
			dialogUI.ClearedCheckBox->palette().color(QPalette::Active, 
			              QPalette::Foreground));
	dialogUI.ClearedCheckBox->setPalette(newPalette);


I recommend checking out the following:

http://doc.trolltech.com/4.0/qpalette.html#details

http://doc.trolltech.com/4.0/qpalette.html#ColorGroup-enum


Brandy

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

3

Thursday, August 18th 2005, 12:57am

Subclassing the style would probably be the proper way to do it (as it would change the behaviour globally).

bhobbs

Beginner

  • "bhobbs" is female

Posts: 15

Location: Lincoln, NE

Occupation: engineering intern at EFJohnson

  • Send private message

4

Thursday, August 18th 2005, 2:18pm

Yeah, that might be a better option in your case since you want to apply it to all line edits. I only wanted to do it for one checkbox.

There's a good example of this in the QStyle docs: http://doc.trolltech.com/4.0/qstyle.html#details