From d0317f4739d35f24167275d32ded6d4068b783d1 Mon Sep 17 00:00:00 2001 From: Alexis Murzeau Date: Sun, 16 Jul 2023 23:24:02 +0200 Subject: [PATCH] damc_gui: set sliders to 0 on double click --- damc_gui/DoubleClickSlider.cpp | 19 ++++++++++++++++++ damc_gui/DoubleClickSlider.h | 13 +++++++++++++ damc_gui/OutputController.ui | 35 +++++++++++++++++++--------------- 3 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 damc_gui/DoubleClickSlider.cpp create mode 100644 damc_gui/DoubleClickSlider.h diff --git a/damc_gui/DoubleClickSlider.cpp b/damc_gui/DoubleClickSlider.cpp new file mode 100644 index 0000000..be995c6 --- /dev/null +++ b/damc_gui/DoubleClickSlider.cpp @@ -0,0 +1,19 @@ +// From https://stackoverflow.com/questions/52550633/how-to-emit-a-signal-if-double-clicking-on-slider-handle + +#include "DoubleClickSlider.h" +#include + +DoubleClickSlider::DoubleClickSlider(QWidget* parent) : QSlider(parent) {} + +void DoubleClickSlider::mouseDoubleClickEvent(QMouseEvent* event) { + QStyleOptionSlider opt; + this->initStyleOption(&opt); + QRect sr = this->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); + + if(sr.contains(event->pos())) { + printf("Set slider to 0\n"); + setValue(0); + } else { + QSlider::mouseDoubleClickEvent(event); + } +} \ No newline at end of file diff --git a/damc_gui/DoubleClickSlider.h b/damc_gui/DoubleClickSlider.h new file mode 100644 index 0000000..f7dfc9c --- /dev/null +++ b/damc_gui/DoubleClickSlider.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +class DoubleClickSlider : public QSlider { + Q_OBJECT +public: + DoubleClickSlider(QWidget* parent = nullptr); + +protected: + void mouseDoubleClickEvent(QMouseEvent* event) override; +}; \ No newline at end of file diff --git a/damc_gui/OutputController.ui b/damc_gui/OutputController.ui index 3ab17fa..7802c81 100644 --- a/damc_gui/OutputController.ui +++ b/damc_gui/OutputController.ui @@ -6,7 +6,7 @@ 0 0 - 62 + 70 391 @@ -94,6 +94,19 @@ 0 + + + + Qt::Horizontal + + + + 77 + 20 + + + + @@ -116,20 +129,7 @@ - - - Qt::Horizontal - - - - 77 - 20 - - - - - - + -80 @@ -365,6 +365,11 @@
FastLabelWidget.h
1 + + DoubleClickSlider + QSlider +
DoubleClickSlider.h
+
muteButton