View Full Version : Get Color from LineEdit
raphaelf
15th May 2007, 14:03
Hello everybody,
OS:Winxp
QT 4.1.3
I can set a color to a lineedit, now i would like to get the color. is this possible?
set color:
ui.l1_le->setPaletteBackgroundColor("yellow");
get color:
?????
Thanks :)
wysota
15th May 2007, 14:20
paletteBackgroundColor()
ui.l1_le->setPaletteBackgroundColor("yellow");
QWidget::setPaletteBackgroundColor() is a Qt3 support member.
// set
QPalette palette = ui.l1_le->palette();
palette.setColor(ui.l1_le->backgroundRole(), Qt::yellow);
ui.l1_le->setPalette(palette);
// get
QColor color = ui.l1_le->palette().color(ui.l1_le->backgroundRole());
Instead of "ui.l1_le->backgroundRole()" you may also directly use QPalette::Base (http://doc.trolltech.com/4.2/qpalette.html#ColorRole-enum) which is used as a background role of text entry widgets.
raphaelf
15th May 2007, 14:49
Hello,
Thank you very much..
But how could i convert it to String?
For this for example:
QColor color = ui.l1_le->palette().color(ui.l1_le->backgroundRole());
QMessageBox::information(this,"LernIT",color);
raphaelf
15th May 2007, 15:30
I could solve my problem like that:
Thanks :D
QColor color = ui.l1_le->palette().color(ui.l1_le->backgroundRole());
//QMessageBox::information(this,"LernIT",QString::number(a));
if (color == "#ffff00")
insert();
else
solve();
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.