我写过的是在窗口标题栏实时显示系统时间,要让QDateTimeEdit现实也应该类似吧。以下是代码,希望能给你个参考
窗口构造函数里面添加:
timer = new QTimer(this);
timer->start(1000);
time = QDateTime::currentDateTime();
this->setWindowTitle(time.time().toString("hh:mm AP"));
connect(timer,SIGNAL(timeout()),this,SLOT(showCurrentTime()));
slot函数:
void MainMenu::showCurrentTime()
{
time = QDateTime::currentDateTime();
this->setWindowTitle(time.time().toString("h:m AP"));
}