Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] --Digital Clock not displaying properly in QDockWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] --Digital Clock not displaying properly in QDockWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 992 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    codewriter
    wrote on last edited by
    #1

    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(timeout()), this, SLOT(showTime()));
    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      codewriter
      wrote on last edited by
      #2

      It turns out that one may disable all features of a QDockWidget by doing
      clockDock->setFeatures(QDockWidget::NoDockWidgetFeatures); or set only desired features by doing clockDock->setFeatures(QDockWidget::DockWidgetMovable |
      QDockWidget::DockWidgetFloatable); //DockWidgetClosable

      and the reason the digital clock was not displaying hh:mm:ss when the example app displayed hh:mm without a problem is because the QLCDNumber class only displays 5 "digits" by default. In this case each "digit" correlates to the number of characters returned by
      QString text = time.toString("hh:mm:ss");
      There are 8 characters in text variable, so I increased the DigitCount attribute from 5 to 8 by doing
      setDigitCount(8);
      and the whole time format gets displayed properly.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved