(Solved)The background-color of the QLineEdit
-
wrote on 20 Dec 2010, 09:01 last edited by
Hello, everyone.
I met a problem that I could not set the background-color of the QLineEdit as well as I put the QLineEdit on a widget.
and the widget is put on the QMainWindow.Both I set the style sheet"background:white" and "background:white", the color of the LineEidt is the widget's background-color.
any suggestions? thanks.
best regards.
hisong -
wrote on 20 Dec 2010, 09:04 last edited by
Are you working on maemo? I had similar problem in my application ("this thread":http://developer.qt.nokia.com/forums/viewthread/2360/), and it seems to be that this is a bug in Qt (I have not created the bug report in the bug tracker yet, as I have not had time to validate the issue and make it more specific).
-
wrote on 20 Dec 2010, 09:06 last edited by
To match all the QLineEdits, you must use the class selector:
@
.QLineEdit
@
or
@
*[class~="QLineEdit"]
@ -
wrote on 20 Dec 2010, 09:18 last edited by
or just:
@
lineEdit->setStyleSheet("QLineEdit{background: black;}");
@ -
wrote on 20 Dec 2010, 10:31 last edited by
Thanks for all replies.
I use the setStyleSheet funtion like
@
lineEdit->setStyleSheet("QLineEdit{background: white;}");
@ to set the background-color white;
but it doesn't work.and I try
@
QLineEdit {
background: qradialgradient(cx:0, cy:0, radius: 1,
fx:0.5, fy:0.5, stop:0 white, stop:1 rgba(0,190,0, 60%));
border-radius: 9px;
}
@it worked.
but the color is not what I need. -
wrote on 20 Dec 2010, 10:56 last edited by
Which OS is this happening?
-
wrote on 20 Dec 2010, 11:46 last edited by
I test the app on Nokia device 5230. The OS is s60v5.
-
wrote on 20 Dec 2010, 12:04 last edited by
I just tested this on latest Qt 4.7.x and it works. When you set the background color as a stylesheet, the lineEdit will lose the themed graphics (including borders etc) as theme graphics are coming from native side and QS60Style cannot make changes to those. So it is either stylesheeted background, borders etc. or theme graphics.
My code was:
@
QString lineEditStyle("QLineEdit {background: white;}");
QLineEdit *testLineEdit = new QLineEdit(this);
testLineEdit->setStyleSheet(lineEditStyle);
@In case you can't get white background visible for the line edit with that code, what Qt version you have?
-
wrote on 20 Dec 2010, 12:47 last edited by
It worked for me as well... are you trying to change the border-color? or the whole background?
-
wrote on 21 Dec 2010, 04:32 last edited by
I solved the problem from another aspect....It seems it is not the best way.
as I first set the background-image of the widget on the QMainWindow, and put the widget() on the QMainWindow, the background-color of QLineEdit was disable.
So I use QPainter to paint the image I use as the background-image on the widget, and then put the widget on the QMainWindow. and put the lineEdit's background-color white:
@
lineEdit->setStyleSheet("QLineEdit{background: white;}");
@It worked.
8/10