From 191ac31598ccc9d7c8a2c83730755714f903b7ca Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 9 Dec 2019 12:07:00 +0100 Subject: Modernize shapedclock example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø Reviewed-by: Andy Shaw --- examples/widgets/widgets/shapedclock/shapedclock.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'examples/widgets/widgets/shapedclock/shapedclock.cpp') 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); @@ -122,6 +123,10 @@ void ShapedClock::paintEvent(QPaintEvent *) painter.translate(width() / 2, height() / 2); 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); @@ -168,6 +173,6 @@ void ShapedClock::resizeEvent(QResizeEvent * /* event */) //! [5] QSize ShapedClock::sizeHint() const { - return QSize(100, 100); + return QSize(200, 200); } //! [5] -- cgit v1.2.3