Files
handleaiuinew/HanddleAI/HandleAiUi-new/uiModule/components/fancyLogWindow.h
T
2024-08-14 11:15:16 +08:00

35 lines
1.0 KiB
C++

#include <QApplication>
#include <QMainWindow>
#include <QTextEdit>
#include <QDateTime>
class LogWindow : public QMainWindow {
public:
LogWindow(QWidget* parent = nullptr) : QMainWindow(parent) {
// 创建日志框
logTextEdit = new QTextEdit(this);
logTextEdit->setReadOnly(true); // 设置为只读
// 设置主窗口布局
setCentralWidget(logTextEdit);
}
// 添加日志信息
void addLog(const QString& message) {
QString text = "<span style='color: yellow;'>" + getCurrentDate() + "</span> "
"<span style='color: yellow;'>" + getCurrentTime() + "</span> "
"<span style='color: white;'>" + message + "</span> ";
logTextEdit->append(text);
}
QString getCurrentTime() {
QTime currentTime = QTime::currentTime();
return currentTime.toString("HH:mm:ss.zzz");
}
QString getCurrentDate() {
QDate currentDate = QDate::currentDate();
return currentDate.toString("yyyy-MM-dd");
}
private:
QTextEdit* logTextEdit;
};