From 77f51098f61b1706337bbf5ca350fefd9163614a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Wed, 23 Oct 2024 18:31:56 +0200 Subject: [PATCH] Code cleanup While QWidget:palette() and QPalette() should technically provide the same results due to the way how the default QPalette gets applied, make it clean and obvious what we want to achieve. --- src/GUI/graphview.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/GUI/graphview.cpp b/src/GUI/graphview.cpp index f887d7d3..063c6de8 100644 --- a/src/GUI/graphview.cpp +++ b/src/GUI/graphview.cpp @@ -46,6 +46,8 @@ static inline QPoint POS(QMouseEvent *e) GraphView::GraphView(QWidget *parent) : QGraphicsView(parent) { + const QPalette &p = palette(); + _scene = new GraphicsScene(this); setScene(_scene); @@ -53,7 +55,7 @@ GraphView::GraphView(QWidget *parent) setRenderHint(QPainter::Antialiasing, true); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setBackgroundBrush(QBrush(palette().brush(QPalette::Base))); + setBackgroundBrush(QBrush(p.brush(QPalette::Base))); viewport()->setAttribute(Qt::WA_AcceptTouchEvents); grabGesture(Qt::PinchGesture); @@ -72,8 +74,7 @@ GraphView::GraphView(QWidget *parent) _info = new InfoItem(); _grid = new GridItem(); _message = new QGraphicsSimpleTextItem(tr("Data not available")); - _message->setBrush(QPalette().brush(QPalette::Disabled, - QPalette::WindowText)); + _message->setBrush(p.brush(QPalette::Disabled, QPalette::WindowText)); connect(_slider, &SliderItem::positionChanged, this, &GraphView::emitSliderPositionChanged); @@ -627,9 +628,9 @@ void GraphView::setSliderColor(const QColor &color) void GraphView::changeEvent(QEvent *e) { if (e->type() == QEvent::PaletteChange) { - _message->setBrush(QPalette().brush(QPalette::Disabled, - QPalette::WindowText)); - setBackgroundBrush(QBrush(palette().brush(QPalette::Base))); + const QPalette &p = palette(); + _message->setBrush(p.brush(QPalette::Disabled, QPalette::WindowText)); + setBackgroundBrush(QBrush(p.brush(QPalette::Base))); } QGraphicsView::changeEvent(e);