PDA

View Full Version : Colored messages in QStatusBar



MCon
4th February 2016, 13:04
I want certain status message to stand-out in status bar.
Best option would be to color-code them (red for errors, blue for warning, gray for debug, ...).
I tried something along the lines:
ui->statusBar->showMessage(QString("<p style=\"color:red\">%1</p>").arg(te->msg));, but it doesn't work because apparently showMessage() does not support rich text.

I know I could use the stylesheet attached to statusBar, but that has two drawbacks:

it would apply to the whole statusBar and not just to the current temporary message.
it would not reset automatically for next message.


What is the right way to tackle this problem?
TiA!

anda_skoa
4th February 2016, 14:38
You could try "<font color='red'>%1</font>" or using "#ff0000" as the color.
Maybe it just doesn't do the paragraph styling.

For styleshee it might be possible to not make it apply to any children.

Or you could specifically set the normal application palette on all widgets that you add but have a special palette on the statusbar that changes foreground color as needed.

Cheers,
_

MCon
5th February 2016, 10:23
Thanks anda_skoa,
unfortunately that does not work.

Apparently showMessage() completely ignores rich text. I see all tags (i.e.: "<html><head/><body><whatever>...") printed as-is in status line.

The only solution I've found so far is to subclass StatusBar and reimplement showMessage() modifying palette with each call.
Is it really necessary to do such an intrusive modification "just" to have colored messages?