summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2019-12-09 12:07:00 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2019-12-10 00:38:40 +0100
commit191ac31598ccc9d7c8a2c83730755714f903b7ca (patch)
treed7b8aa99fd2a2e13802ae1ebc6e85124ffce8159 /examples/widgets/widgets
parent03dc30acca4976c716c723ff46d503d35459b2a0 (diff)
Modernize shapedclock example
Relying on the hard clipping of QRegion widget masks to create non-rectangular windows is a solution from a bygone era. The result looks horrible with today's eyes, particularly on a high-dpi screen. Update the example to create smooth anti-aliased edges using translucent window bacground. Task-number: QTBUG-64229 Change-Id: I8859d61177d2a2dc446632c23f27f42050e0d7c7 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'examples/widgets/widgets')
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/examples/widgets/widgets/shapedclock/shapedclock.cpp b/examples/widgets/widgets/shapedclock/shapedclock.cpp
index 3c78f4da89..673d1a218f 100644
--- a/examples/widgets/widgets/shapedclock/shapedclock.cpp
+++ b/examples/widgets/widgets/shapedclock/shapedclock.cpp
@@ -61,6 +61,7 @@
ShapedClock::ShapedClock(QWidget *parent)
: QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint)
{
+ setAttribute(Qt::WA_TranslucentBackground);
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, QOverload<>::of(&ShapedClock::update));
timer->start(1000);
@@ -123,6 +124,10 @@ void ShapedClock::paintEvent(QPaintEvent *)
painter.scale(side / 200.0, side / 200.0);
painter.setPen(Qt::NoPen);
+ painter.setBrush(palette().window());
+ painter.drawEllipse(QPoint(0, 0), 98, 98);
+
+ painter.setPen(Qt::NoPen);
painter.setBrush(hourColor);
painter.save();
@@ -168,6 +173,6 @@ void ShapedClock::resizeEvent(QResizeEvent * /* event */)
//! [5]
QSize ShapedClock::sizeHint() const
{
- return QSize(100, 100);
+ return QSize(200, 200);
}
//! [5]