10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
... class MainWindow : public QMainWindow { Q_OBJECT public : // Systen Defined MainWindow(QWidget *parent = nullptr ); ~MainWindow(); void timerEvent(QTimerEvent *); // Timer事件處理程序 // ------------------------------------------------- // User Defined void system_initial(); // 應用程式初始化變數 void tasks_1s(); // 1秒處理之Tasks private : Ui::MainWindow *ui; QLabel *currentTimeLabel; // 建立一個顯示時間的Label ... |
1 2 3 4 5 6 7 8 9 10 |
... // 設定 textEdit_log 為 HTML 格式,能接受彩色 ui->textEdit_Log->setHtml( "" ); // 宣告 1 秒的Timer timer_1s = startTimer(1000); currentTimeLabel = new QLabel; // 顯示時間的Label元件宣告 ui->statusbar->addWidget(currentTimeLabel); // 在狀態欄中加入顯示時間的Label元件 ... |
1 2 3 4 5 6 7 8 |
void MainWindow::tasks_1s() { //ui->textEdit_Log->append("timer event."); // Update Date & Time QDateTime current_time = QDateTime::currentDateTimeUtc(); // 獲得目前UTC時間 QString timestr = current_time.toString( "yyyy-MM-ddThh:mm:ssZ" ); // 設定顯示時間的格式 currentTimeLabel->setText(timestr); // 更新狀態欄中現在時間 } |