From d07b45f50a9d05d91b27ef4a1488cd1910f45f31 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Mon, 14 Jun 2021 23:42:59 +0800 Subject: [PATCH] OnroadAlerts: construct QPainter only when needed (#21260) --- selfdrive/ui/qt/onroad.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index b4c9b8919..94e0e085e 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -148,8 +148,6 @@ void OnroadAlerts::stopSounds() { } void OnroadAlerts::paintEvent(QPaintEvent *event) { - QPainter p(this); - if (alert_size == cereal::ControlsState::AlertSize::NONE) { return; } @@ -161,6 +159,8 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) { int h = alert_sizes[alert_size]; QRect r = QRect(0, height() - h, width(), h); + QPainter p(this); + // draw background + gradient p.setPen(Qt::NoPen); p.setCompositionMode(QPainter::CompositionMode_SourceOver);