Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [Solved]To display system clock time in LCD format
QtWS25 Last Chance

[Solved]To display system clock time in LCD format

Scheduled Pinned Locked Moved Language Bindings
7 Posts 4 Posters 9.8k Views
  • 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.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by
    #1

    To display system clock time in LCD format
    I just want to display system clock time in LCD format, also want the time to be displayed with the format of hh:mm:ss ,my code is as following ,but when I run it ,it is out of my expectaions ,so anyone can explain why ?

    @import sys
    from PyQt4 import QtGui, QtCore

    class Example(QtGui.QWidget):

    def __init__(self): 
        super(Example, self).__init__() 
        self.initUI() 
        timer = QtCore.QTimer(self) 
        timer.timeout.connect(self.showlcd) 
        timer.start(1000) 
        self.showlcd() 
    
    def initUI(self): 
        
        self.lcd = QtGui.QLCDNumber(self) 
        self.setGeometry(30, 30, 800, 600) 
        self.setWindowTitle('Time') 
    
        vbox = QtGui.QVBoxLayout() 
        vbox.addWidget(self.lcd) 
        self.setLayout(vbox) 
    
        self.show() 
        
    def showlcd(self): 
        time = QtCore.QTime.currentTime() 
        text = time.toString('hh:mm:ss') 
        self.lcd.display(text) 
    

    def main():

    app = QtGui.QApplication(sys.argv) 
    ex = Example() 
    sys.exit(app.exec_()) 
    

    if name == 'main':
    main()
    @

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      [quote author="redstoneleo" date="1349317955"]want the time to be displayed with the format of hh:mm:ss

      ...
      @text = time.toString('hh:mm')@
      [/quote]You want hh:mm:ss, but you wrote hh:mm. Is that the cause? If not, please describe what happens when you run your program, and why "it is out of my expectaions".

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redstoneleo
        wrote on last edited by
        #3

        [quote author="JKSH" date="1349318198"][quote author="redstoneleo" date="1349317955"]want the time to be displayed with the format of hh:mm:ss ... @text = time.toString('hh:mm')@ [/quote]You want hh:mm:ss, but you wrote hh:mm. Is that the cause? If not, please describe what happens when you run your program, and why "it is out of my expectaions". [/quote]

        text = time.toString('hh:mm:ss')

        doesn't work ? why?

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          -Hmm, I just realized, QLCDNumber can only display numbers. It can't display ":"-

          Edit: Sorry, yes it can: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qlcdnumber.html

          But, you need to describe what you see. Otherwise, I can't guess what's wrong.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • jazzycamelJ Offline
            jazzycamelJ Offline
            jazzycamel
            wrote on last edited by
            #5

            You need to set the digit count on the LCD to have enough room for all 8 characters of the system time "hh:mm:ss". The default digit count is 5, thus why you are only seeing "mm:ss". I did something very similar a while back as follows:

            @
            from PyQt4.QtGui import QApplication, QWidget, QVBoxLayout, QLCDNumber
            from PyQt4.QtCore import QTime

            class SystemClock(QWidget):
            def init(self, parent=None):
            QWidget.init(self, parent)

                self.setWindowTitle("System Clock")
                self.resize(640,240)
            
                l=QVBoxLayout(self)
                self.lcd=QLCDNumber(self, digitCount=8)
                l.addWidget(self.lcd)
            
                self.startTimer(1000)
            
            def timerEvent(self, e): 
                self.lcd.display(QTime.currentTime().toString("hh:mm:ss"))
            

            if name=="main":
            from sys import argv, exit
            a=QApplication(argv)
            s=SystemClock()
            s.show()
            exit(a.exec_())
            @

            For the avoidance of doubt:

            1. All my code samples (C++ or Python) are tested before posting
            2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
            1 Reply Last reply
            0
            • R Offline
              R Offline
              redstoneleo
              wrote on last edited by
              #6

              thanks all your replies ,now it worked in jazzycamel 's way .thanks!!!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Macro
                wrote on last edited by
                #7

                Please Edit your Question and prepend /append [Solved] to it.

                Thanks & Regards..

                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