summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Rauter <matthias.rauter@qt.io>2023-11-13 10:39:12 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-11-17 18:50:47 +0000
commitdcec70a7c09bb87de5a86f5ccf79cc252466b7ac (patch)
tree3143d8c718e7c0031ac44ce896bd8c8abf780042
parent31001fd896e73e4355e8901cec96bf651b6f4420 (diff)
Refurbish the custom widget example
The custom widget has the appearance of the analog clock, which was refurbished with 619ec1a6406a8be7bfa9d96b9e693e7a3323d8dc. This change applies the refurbished design to the custom widget. Task: QTBUG-118871 Change-Id: I4a751a54d91d7eaa13f2282a9f1a1a26d91a204c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit b420e7aeb5327b4ee7c5de85cfa6ecbe050cab0d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/designer/customwidgetplugin/analogclock.cpp57
-rw-r--r--examples/designer/doc/images/customwidgetplugin-example.webpbin9260 -> 26828 bytes
2 files changed, 40 insertions, 17 deletions
diff --git a/examples/designer/customwidgetplugin/analogclock.cpp b/examples/designer/customwidgetplugin/analogclock.cpp
index 23461edbf..590fe6efa 100644
--- a/examples/designer/customwidgetplugin/analogclock.cpp
+++ b/examples/designer/customwidgetplugin/analogclock.cpp
@@ -22,48 +22,71 @@ AnalogClock::AnalogClock(QWidget *parent)
void AnalogClock::paintEvent(QPaintEvent *)
{
- static const QPoint hourHand[3] = {{7, 8}, {-7, 8}, {0, -40}};
- static const QPoint minuteHand[3] = {{7, 8}, {-7, 8}, {0, -70}};
-
- QColor hourColor(127, 0, 127);
- QColor minuteColor(0, 127, 127, 191);
-
- const int side = qMin(width(), height());
- QTime time = QTime::currentTime();
+ static const QPoint hourHand[4] = {
+ QPoint(5, 14),
+ QPoint(-5, 14),
+ QPoint(-4, -71),
+ QPoint(4, -71)
+ };
+ static const QPoint minuteHand[4] = {
+ QPoint(4, 14),
+ QPoint(-4, 14),
+ QPoint(-3, -89),
+ QPoint(3, -89)
+ };
+ static const QPoint secondsHand[4] = {
+ QPoint(1, 14),
+ QPoint(-1, 14),
+ QPoint(-1, -89),
+ QPoint(1, -89)
+ };
+
+ const QColor hourColor(palette().color(QPalette::Text));
+ const QColor minuteColor(palette().color(QPalette::Text));
+ const QColor secondsColor(palette().color(QPalette::Accent));
+
+ int side = qMin(width(), height());
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.translate(width() / 2, height() / 2);
painter.scale(side / 200.0, side / 200.0);
+ QTime time = QTime::currentTime();
+
painter.setPen(Qt::NoPen);
painter.setBrush(hourColor);
painter.save();
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
- painter.drawConvexPolygon(hourHand, 3);
+ painter.drawConvexPolygon(hourHand, 4);
painter.restore();
- painter.setPen(hourColor);
-
for (int i = 0; i < 12; ++i) {
- painter.drawLine(88, 0, 96, 0);
+ painter.drawRect(73, -3, 16, 6);
painter.rotate(30.0);
}
- painter.setPen(Qt::NoPen);
painter.setBrush(minuteColor);
painter.save();
- painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
- painter.drawConvexPolygon(minuteHand, 3);
+ painter.rotate(6.0 * time.minute());
+ painter.drawConvexPolygon(minuteHand, 4);
+ painter.restore();
+
+ painter.setBrush(secondsColor);
+
+ painter.save();
+ painter.rotate(6.0 * time.second());
+ painter.drawConvexPolygon(secondsHand, 4);
+ painter.drawEllipse(-3, -3, 6, 6);
+ painter.drawEllipse(-5, -68, 10, 10);
painter.restore();
painter.setPen(minuteColor);
for (int j = 0; j < 60; ++j) {
- if ((j % 5) != 0)
- painter.drawLine(92, 0, 96, 0);
+ painter.drawLine(92, 0, 96, 0);
painter.rotate(6.0);
}
}
diff --git a/examples/designer/doc/images/customwidgetplugin-example.webp b/examples/designer/doc/images/customwidgetplugin-example.webp
index 52a83c364..a867ff886 100644
--- a/examples/designer/doc/images/customwidgetplugin-example.webp
+++ b/examples/designer/doc/images/customwidgetplugin-example.webp
Binary files differ