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.
void ViewLabel
::enterEvent(QEvent *e
) {
//setBackgroundRole(QPalette::Dark);
setPalette(pal);
}
void ViewLabel
::leaveEvent(QEvent *e
) {
//setBackgroundRole(QPalette::Light);
setPalette(pal);
}
void ViewLabel::enterEvent(QEvent *e)
{
QLabel::enterEvent(e);
QPalette pal;
//setBackgroundRole(QPalette::Dark);
pal.setColor(QPalette::WindowText,QColor(Qt::white));
pal.setColor(QPalette::Base,QColor(Qt::darkGray));
pal.setColor(QPalette::Window,QColor(Qt::darkGray));
setPalette(pal);
}
void ViewLabel::leaveEvent(QEvent *e)
{
QLabel::leaveEvent(e);
QPalette pal;
//setBackgroundRole(QPalette::Light);
pal.setColor(QPalette::WindowText,QColor(Qt::darkGray));
pal.setColor(QPalette::Base,QColor(Qt::white));
pal.setColor(QPalette::Window,QColor(Qt::white));
setPalette(pal);
}
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.
Bookmarks