Results 1 to 3 of 3

Thread: statusBar() message color change

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question statusBar() message color change

    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.

    Qt Code:
    1. void MainWin::DisplayStatus( QString sStatus, QColor rgbColor, int duration )
    2. {
    3. if ( !sStatus.isEmpty() )
    4. {
    5. QPalette palette;
    6. palette.setColor( QPalette::WindowText, rgbColor );
    7. statusBar()->setPalette( palette );
    8. statusBar()->showMessage( sStatus, duration );
    9.  
    10. // resets the palette before the message can be seen in the previous color
    11. if ( rgbColor != COLOR_StatusNorm )
    12. {
    13. palette.setColor( QPalette::WindowText, COLOR_StatusNorm );
    14. statusBar()->setPalette( palette );
    15. }
    16. }
    17. }
    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: statusBar() message color change

    Why don't you use a singleshot timer with the same duration as the status message?
    You start the timer right after you set a new status message.

    Connect a slot to its timeout signal and in that slot change the color back.

    Since the timer and the message have the same timeout, there should be a slight delay( the order of milliseconds) between the message timeout and timer timeout, but really, no one is going to notice that.

    regards

  3. The following user says thank you to marcel for this useful post:

    mclark (8th August 2007)

  4. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: statusBar() message color change

    Thanks Marcel, that looks like just the solution I need.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.