I took the dockWidgets example app and combined it with the digitalclock app so I could display hours:minutes:seconds in the dockwidget.
All is well, but the clock only shows minutes:seconds in the dockwidget.
here’s my dockwidget code in the mainwindow
//================================================
QDockWidget *clockDock = new QDockWidget(this);
clockDock->setFixedWidth(520);
clockDock->setFixedHeight(100);
//clockDock->set
clockDock->setAllowedAreas(Qt::LeftDockWidgetArea);
DigitalClock *digitalClock = new DigitalClock(clockDock);
clockDock->setWidget(digitalClock);
addDockWidget(Qt::LeftDockWidgetArea, clockDock);
//================================================
and here’s the digital clock class:
//=================================================
#include <QtWidgets>
#include “digitalclock.h”
//! [0]
DigitalClock::DigitalClock(QWidget *parent)
: QLCDNumber(parent)
{
setSegmentStyle(Filled);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL), this, SLOT));
timer->start(1000);
showTime();
//setWindowTitle(tr(“Digital Clock”));
//resize(150, 60);
}
//! [0]
//! [1]
void DigitalClock::showTime()
//! [1] //! [2]
{
QTime time = QTime::currentTime();
// QString text = time.toString(“hh:mm”);
QString text = time.toString(“hh:mm:ss”);
// if ((time.second() % 2) 0)
// text[2] = ' ';
display(text); // DOES NOT DISPLAY hh:mm:ss, but only mm:ss !!
}
//! [2]
//===============================================
What am I doing wrong?
Also how do I set the dockwidget to be unclosable and unmovable?
↧