Greetings,
I want to be able to change the color of the statusBar message that appears in my QMainWindow object based upon the type of message; normal, warning, error...
The problem I need help with is that I'm also using the timer function of the statusBar. This means that if I change the palette of the statusBar and display the message, I must wait until the timer elapses to change the palette back.
For example, I display a warning message (forces a palette change to blue). If, after I show the message, I change the palette back, the palette switching happens so fast that the string never appears in the warning color.
void MainWin
::DisplayStatus( QString sStatus,
QColor rgbColor,
int duration
) {
if ( !sStatus.isEmpty() )
{
palette.
setColor( QPalette::WindowText, rgbColor
);
statusBar()->setPalette( palette );
statusBar()->showMessage( sStatus, duration );
// resets the palette before the message can be seen in the previous color
if ( rgbColor != COLOR_StatusNorm )
{
palette.
setColor( QPalette::WindowText, COLOR_StatusNorm
);
statusBar()->setPalette( palette );
}
}
}
void MainWin::DisplayStatus( QString sStatus, QColor rgbColor, int duration )
{
if ( !sStatus.isEmpty() )
{
QPalette palette;
palette.setColor( QPalette::WindowText, rgbColor );
statusBar()->setPalette( palette );
statusBar()->showMessage( sStatus, duration );
// resets the palette before the message can be seen in the previous color
if ( rgbColor != COLOR_StatusNorm )
{
palette.setColor( QPalette::WindowText, COLOR_StatusNorm );
statusBar()->setPalette( palette );
}
}
}
To copy to clipboard, switch view to plain text mode
If I don't reset the statusBar palette, all subsequent messages will use the warning color.
Most of the messages have a duration of 3-5 seconds so a Sleep() is not appropriate.
Does anyone have suggestions or am I trying to do something the statusBar was not intended for?
Bookmarks