Results 1 to 3 of 3

Thread: Colored messages in QStatusBar

  1. #1
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Colored messages in QStatusBar

    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:
    Qt Code:
    1. ui->statusBar->showMessage(QString("<p style=\"color:red\">%1</p>").arg(te->msg));
    To copy to clipboard, switch view to plain text mode 
    , 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:
    1. it would apply to the whole statusBar and not just to the current temporary message.
    2. it would not reset automatically for next message.


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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Colored messages in QStatusBar

    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,
    _

  3. #3
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Colored messages in QStatusBar

    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?

Similar Threads

  1. QTextEdit colored text, again...
    By nsvinc in forum Qt Programming
    Replies: 1
    Last Post: 29th December 2015, 17:00
  2. How to get colored QImage
    By Nadja in forum Newbie
    Replies: 3
    Last Post: 13th August 2012, 10:29
  3. Write colored text
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2010, 12:55
  4. Colored cursor
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 15th May 2008, 12:16
  5. Colored Buttons
    By Walsi in forum Newbie
    Replies: 33
    Last Post: 8th December 2007, 12:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.