Hi,

I have a widget whose background color is set to white using

setBackgroundRole(QPalette::Light);

This widget has a few QLabels on it. These label should change its text color and the background to some other color when mouse over and should have white background and darkGray text when mouse is not over it. For this I have written the following code.

Qt Code:
  1. void ViewLabel::enterEvent(QEvent *e)
  2. {
  3. QLabel::enterEvent(e);
  4. QPalette pal;
  5. //setBackgroundRole(QPalette::Dark);
  6. pal.setColor(QPalette::WindowText,QColor(Qt::white));
  7. pal.setColor(QPalette::Base,QColor(Qt::darkGray));
  8. pal.setColor(QPalette::Window,QColor(Qt::darkGray));
  9. setPalette(pal);
  10. }
  11.  
  12. void ViewLabel::leaveEvent(QEvent *e)
  13. {
  14. QLabel::leaveEvent(e);
  15. QPalette pal;
  16. //setBackgroundRole(QPalette::Light);
  17. pal.setColor(QPalette::WindowText,QColor(Qt::darkGray));
  18. pal.setColor(QPalette::Base,QColor(Qt::white));
  19. pal.setColor(QPalette::Window,QColor(Qt::white));
  20. setPalette(pal);
  21. }
To copy to clipboard, switch view to plain text mode 

With the above code when mouse goes over the label the background changes to white but the text color is not changing to darkGray. Same thing happens when I use setBackgroundRole.

Can someone please tell me why the text color is not changing ?

Thanks a lot.