PDA

View Full Version : problem with QLineEdit and QPalette



impeteperry
14th October 2008, 20:21
I have defined a QLineEdit in the "BaseForm" constructor as
boxLayout = new QVBoxLayout ( frameD );
inputStripLayout = new QHBoxLayout ( );
boxLayout->addLayout ( inputStripLayout );

lbCategory = new QLabel("Category #");
lbCategory->setFont ( fb );
inputStripLayout->addWidget ( lbCategory );

leCategoryNumber= new QLineEdit();
leCategoryNumber->setAlignment ( Qt::AlignCenter );
leCategoryNumber->setPalette ( palE );
leCategoryNumber->setFont ( fb );
leCategoryNumber->setMaximumWidth(30);
leCategoryNumber->setEnabled(false);

inputStripLayout->addWidget ( leCategoryNumber) and I want to change the color of the QLineEdit and set the focus with
void BaseForm::slotPb1()
{
catNum->inputCatNum();
Pb1->setText("-");
Pb2->setText("Cat'ory");
leCategoryNumber->setPalette ( QColor (17, 255, 255) );
leCategoryNumber->setEnabled(true);
leCategoryNumber->setFocus();
I get the "focus" ok, but I get a "white" box, not the "blue" one I want. Looked at the QPalette" documentation and don't understand a word of it. I am sure there is a simple way to togle colors on a QLineEdit" as a signal for "User" input. But I couldn't find it .
Thanks in advance for you help.

marcel
14th October 2008, 20:55
You can try sylesheets: http://doc.trolltech.com/4.4/stylesheet-examples.html#customizing-qlineedit . It's easier.

impeteperry
15th October 2008, 16:29
Amazing!! "Enhancements to the point of non-usability"

But
The background of a read only QLineEdit can be modified as below:

QLineEdit:read-only {
background: lightblue;
I want to change the color when it has the focus.!!!

munna
15th October 2008, 16:55
I think you will need to re-implement the focusInEvent (http://doc.trolltech.com/4.4/qwidget.html#focusInEvent) and focusOutEvent (http://doc.trolltech.com/4.4/qwidget.html#focusOutEvent) of QWidget. In these methods you will have to write code to change the palette of the QLineEdit.

pdolbey
15th October 2008, 17:05
The stylesheet documentation http://doc.trolltech.com/4.4/stylesheet-reference.html shows you can use the "focus" state like so



QLineEdit:focus {
background: lightblue;
}


Haven't tried it (I'm still at work) but it should work

Pete