简体   繁体   中英

In QT gui, how do you change the color of specified text in a QStatusBar?

I have a QStatusBar. I have two displays in it... Longitude and Latitude. There is a specified acceptable range for each indicator where I want the text color to be green, and then red for when it falls out of range. Not sure how to go about this especially since it is 2 different indicators in the QStatusBar?

Below is an example that demonstrates how to put labels with colored text in the status bar:

[..]
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QStatusBar sb;

    QLabel lbl1("Text Green");
    lbl1.setStyleSheet("QLabel { color: green }");

    QLabel lbl2("Text Red");
    lbl2.setStyleSheet("QLabel { color: red }");

    sb.addPermanentWidget(&lbl1);
    sb.addPermanentWidget(&lbl2);

    sb.show();

    return app.exec();
}

As you can see, the text color is changing when you set the appropriate style sheet to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM