I have a QGraphicsScene
and add a QlineEdit
but changing color just doesn't work.
QGridLayout *layout = new QGridLayout(this);
QGraphicsView *view = new QGraphicsView(this);
QGraphicsScene *scene = new QGraphicsScene(this);
QWidget *widget = new QWidget();
QGridLayout *widgetLayout = new QGridLayout(this);
QLineEdit *le1 = new QLineEdit(widget);
QLineEdit *le2 = new QLineEdit(widget);
widgetLayout->addWidget(le1,1,0);
widgetLayout->addWidget(le2,2,0);
widget->setLayout(widgetLayout);
QPalette paletteRed = le1->palette();
paletteRed.setColor(QPalette::Background,Qt::red);
QPalette paletteGreen = le1->palette();
paletteGreen.setColor(QPalette::Background,Qt::green);
le1->setAutoFillBackground(true);
le1->setPalette(paletteRed); // not working
widget->setPalette(paletteGreen); // working
view->setScene(scene);
scene->addWidget(widget);
ui->centralWidget->setLayout(layout);
layout->addWidget(view);
Do I have to trigger something like update()
( which is not working either to get another color ) if the widget is in a scene?
EDIT:
created new example Code.
I know this works in a normal QWidget
. Actually the code works fine if i place the QLineEdit
in a normal QFrame
etc but its in a QGraphicsScene
. And in this special case its not working. Text and highlight color etc is also working fine. But backgroud/base/etc ist not.