From 3585f6a53881cdfd5436d55c8f162f05480c5761 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sun, 19 Dec 2021 14:57:18 +0100 Subject: [PATCH] highlight border --- include/soundbutton.h | 3 +++ src/soundbutton.cpp | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/soundbutton.h b/include/soundbutton.h index a491456..ea51aeb 100644 --- a/include/soundbutton.h +++ b/include/soundbutton.h @@ -48,7 +48,10 @@ private: uint64_t lengthms = 0; // ignored when length = 0 float volume = 1.f; + bool highlighted = false; bool disabled = false; + const static uint8_t HIGHLIGHTBORDEROFFSET = 5; + QxtGlobalShortcut* globalShortcut = nullptr; }; \ No newline at end of file diff --git a/src/soundbutton.cpp b/src/soundbutton.cpp index d2b7331..8e45f9b 100644 --- a/src/soundbutton.cpp +++ b/src/soundbutton.cpp @@ -66,26 +66,29 @@ void SoundButton::setVolume(float v) { volume = v; } -void SoundButton::setHighlighted(bool highlighted) { - if(highlighted) { - setStyleSheet("SoundButton { color: red; }"); - //setText("-> " + getInfo()); - } else { - setStyleSheet("SoundButton {}"); - //setText(getInfo()); - } +void SoundButton::setHighlighted(bool highlighted_) { + highlighted = highlighted_; + + repaint(); } void SoundButton::paintEvent(QPaintEvent* event) { QPushButton::paintEvent(event); + QPainter painter(this); + if(highlighted) { + QSize s = size(); + QRect rect(HIGHLIGHTBORDEROFFSET, HIGHLIGHTBORDEROFFSET, s.width()-HIGHLIGHTBORDEROFFSET*2, s.height()-HIGHLIGHTBORDEROFFSET*2); + painter.setPen(QPen(Qt::red)); + painter.drawRect(rect); + } + QString text = ""; // cancel if nothing to print if(text.isEmpty()) return; - QPainter painter(this); painter.setPen(QPen(Qt::white)); QPoint textPos(0, painter.fontMetrics().height()); textPos.rx() = width() - painter.fontMetrics().horizontalAdvance(text) - 6;