aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorCristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2022-08-02 14:30:44 +0200
committerCristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2022-09-19 09:11:24 +0200
commit1cf5d6d13b7edbbc60a162b237731fcfcdc63daf (patch)
treedc33f748b2224cb9cb14f153722367c355193034 /examples/widgets
parented51341bec119d4c7c5d019e0fd8a6d184f7b877 (diff)
examples: add DigitalClock example
This is a port of the Digital Clock Example, with a little modification to include seconds. Pick-to: 6.2 6.3 Task-number: PYSIDE-841 Change-Id: I99c36dd4a542f4aa19af2bce90e08bc941a181e7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/digitalclock/digitalclock.py41
-rw-r--r--examples/widgets/digitalclock/digitalclock.pyproject3
-rw-r--r--examples/widgets/digitalclock/doc/digitalclock-screenshot.pngbin0 -> 726 bytes
-rw-r--r--examples/widgets/digitalclock/doc/digitalclock.rst12
4 files changed, 56 insertions, 0 deletions
diff --git a/examples/widgets/digitalclock/digitalclock.py b/examples/widgets/digitalclock/digitalclock.py
new file mode 100644
index 000000000..f0030b356
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.py
@@ -0,0 +1,41 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+import sys
+
+from PySide6.QtCore import QTime, QTimer, Slot
+from PySide6.QtWidgets import QApplication, QLCDNumber
+
+
+class DigitalClock(QLCDNumber):
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self.setSegmentStyle(QLCDNumber.Filled)
+ self.setDigitCount(8)
+
+ self.timer = QTimer(self)
+ self.timer.timeout.connect(self.show_time)
+ self.timer.start(1000)
+
+ self.show_time()
+
+ self.setWindowTitle("Digital Clock")
+ self.resize(250, 60)
+
+ @Slot()
+ def show_time(self):
+ time = QTime.currentTime()
+ text = time.toString("hh:mm:ss")
+
+ # Blinking effect
+ if (time.second() % 2) == 0:
+ text = text.replace(":", " ")
+
+ self.display(text)
+
+
+if __name__ == "__main__":
+
+ app = QApplication(sys.argv)
+ clock = DigitalClock()
+ clock.show()
+ sys.exit(app.exec())
diff --git a/examples/widgets/digitalclock/digitalclock.pyproject b/examples/widgets/digitalclock/digitalclock.pyproject
new file mode 100644
index 000000000..03c3b6bb7
--- /dev/null
+++ b/examples/widgets/digitalclock/digitalclock.pyproject
@@ -0,0 +1,3 @@
+{
+ "files": ["digitalclock.py"]
+}
diff --git a/examples/widgets/digitalclock/doc/digitalclock-screenshot.png b/examples/widgets/digitalclock/doc/digitalclock-screenshot.png
new file mode 100644
index 000000000..2234d7665
--- /dev/null
+++ b/examples/widgets/digitalclock/doc/digitalclock-screenshot.png
Binary files differ
diff --git a/examples/widgets/digitalclock/doc/digitalclock.rst b/examples/widgets/digitalclock/doc/digitalclock.rst
new file mode 100644
index 000000000..ef800d9c0
--- /dev/null
+++ b/examples/widgets/digitalclock/doc/digitalclock.rst
@@ -0,0 +1,12 @@
+Digital Clock Example
+=====================
+
+The Digital Clock example shows how to use QLCDNumber to display a number with
+LCD-like digits.
+
+.. image:: digitalclock-screenshot.png
+ :width: 400
+ :alt: Digital Clock Screenshot
+
+This example also demonstrates how QTimer can be used to update a widget at
+regular intervals.