mercredi 6 décembre 2017

Color of std::stringstream inside QPlainText

How can I set the color of std::stringstream insider QPlainText?

Here is my code:

#ifndef _COLORS_
#define _COLORS_

/* FOREGROUND */
#define RST  "\x1B[0m"
#define KRED  "\x1B[31m"
#define KGRN  "\x1B[32m"
#define KYEL  "\x1B[33m"
#define KBLU  "\x1B[34m"
#define KMAG  "\x1B[35m"
#define KCYN  "\x1B[36m"
#define KWHT  "\x1B[37m"

#define FRED(x) KRED x RST
#define FGRN(x) KGRN x RST
#define FYEL(x) KYEL x RST
#define FBLU(x) KBLU x RST
#define FMAG(x) KMAG x RST
#define FCYN(x) KCYN x RST
#define FWHT(x) KWHT x RST

#define BOLD(x) "\x1B[1m" x RST
#define UNDL(x) "\x1B[4m" x RST

#endif  /* _COLORS_ */

std::stringstream output;
    output << day << "." << month << "." << year << "\n";
    output << hour << ":" << minute << ":" << seconds << "\n";
    output << "Höhe: Baro" << "\n";
    output << "DL: " << downlink_counter << "\n";
    if(gps_satellite_count > 11){
        std::string point = FBLU("I'm blue.");
        output << "GPS: " << point << "\n";
    }
    output << "ff:ff:ff" << "\n";
    output << "Video - Mitte" << "\n";

    double lat = latitude_wgs84_radians * 180 / M_PI, lon = longitude_wgs84_radians * 180 / M_PI;
    int zone;
    bool northp;
    double x, y;
    UTMUPS::Forward(lat, lon, zone, northp, x, y);
    std::string mgrs;
    MGRS::Forward(zone, northp, x, y, lat, 5, mgrs);

    int prec;
    MGRS::Reverse(mgrs, zone, northp, x, y, prec);
    double NewLat, NewLong;
    UTMUPS::Reverse(zone, northp, x, y, NewLat, NewLong);
    // std::cout << NewLat << " " << NewLong << "\n";

    MapView->ownshipPosition(NewLat, NewLong);

    if(KarteBewegen == 0){
        disti::GeoCoord coord;
        double altitude = 0.0;
        coord.SetGeodetic( NewLong, NewLat, altitude );

        MapView->SetViewLocation(coord);
    }
    output << "Ost: " << x << "\n";
    output << "Nord: " << (y / pow(10, 01)) << "\n";
    output << "Grund: " << static_cast<int>(altitude_wgs84_meters) << "m" << std::endl;

    ui->pTE_Verbindung->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->pTE_Verbindung->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->pTE_Verbindung->setPlainText(output.str().c_str());

std::string point = FBLU("I'm blue."); should be blue on the output. What happened is, my program just crashed.

Aucun commentaire:

Enregistrer un commentaire