声明:
class config : public QObject
{
Q_OBJECT
public:
static void initTableView(QTableView* );
static void initQSS();
static config* getinstance();
enum ColorSet{BLUE,RED,GREEN};
static const QString setTextColor(ColorSet,const QString&); //设定不同颜色
private:
static config* instance;
explicit config(QObject *parent = nullptr);
public slots:
void sendDebugInfor(DebugType,const QString& );
signals:
void updateDebugInfor(DebugType,const QString& );
};
实现:
const QString config::setTextColor(ColorSet set,const QString& str)
{
static QString transfer;
switch (set)
{
case RED:
transfer=QString("<font color=\"#FF0000\">%1</font> ").arg(str);
break;
case BLUE:
transfer=QString("<font color=\"#0000FF\">%1</font> ").arg(str);
break;
case GREEN:
transfer=QString("<font color=\"#00FA9A\">%1</font> ").arg(str);
break;
default:
transfer=QString("<font color=\"#FFFFFF\">%1</font> ").arg(str);
}
return transfer;
}
调用:
void widgetTest::on_butStartSend_clicked()
{
config::instance->sendDebugInfor(GREEN,"Start send button clicked");
}
void widgetTest::on_butStopSend_clicked()
{
config::instance->sendDebugInfor(RED,"Stop send button clicked");
}
效果: