Files

35 lines
1.0 KiB
C++
Raw Permalink Normal View History

2024-05-18 23:53:26 +08:00
#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) {
2024-08-07 09:16:35 +00:00
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");
2024-05-18 23:53:26 +08:00
}
private:
QTextEdit* logTextEdit;
};