Hello everybody,

I try to create a window with multiple QLineEdits and QPushbuttons that are grouped. Each group has a different background color, like, QLineEdits 1-5 are green and its corresponding QPushButton is also green, QLineEdits 6-10 are red and so does its corresponding QPushButton.

What I try to achieve now is updating each group by clicking its corresponding QPushButton.
From start, hence build and first display of the window, all QLineEdits should appear with classic white background. After clicking its corresponding QPushButton, they all should update its background color to green/red.

I could now create a new palette for each QLineEdit, but this would result in much work. An easier solution would be a single QPalette.
I noticed that QLineEdit::setPalette() accepts a reference to the QPalette. So afaik changing the palette should affect to every QLineEdit. Unfortunatelly, it doesn't...

Example:
Qt Code:
  1. QLineEdit *edit1 = new QLineEdit;
  2. QLineEdit *edit2 = new QLineEdit;
  3. QPalette palette;
  4.  
  5. palette.setColor(QPalette::Base, QColor(0,255,0);
  6. edit1->setPalette(palette);
  7. palette.setColor(QPalette::Base, QColor(255,0,0);
  8. edit2->setPalette(palette);
To copy to clipboard, switch view to plain text mode 
The result is that edit1 has a green background and edit2 has a red background. Why changing palette from green to red doesn't affect to edit1?
Could the problem be that QLineEdit::setPalette() accepts a CONST reference? I thought that references are always const, because once initialized, they can't be re-initialized...

Maybe someone can help me with that

Kind regards,
Binary