Skip to content

Commit

Permalink
Prevent tooltip flickering
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujan committed Jan 14, 2023
1 parent 35f570b commit fbc327a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plugin-volume/volumepopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ VolumePopup::VolumePopup(QWidget* parent):
connect(m_muteToggleButton, &QPushButton::clicked, this, &VolumePopup::handleMuteToggleClicked);

mWheelTimer->setSingleShot(true);
mWheelTimer->setInterval(400); // "QStyle::SH_ToolTip_WakeUpDelay" is 700 by default
mWheelTimer->setInterval(350); // "QStyle::SH_ToolTip_WakeUpDelay" is 700 by default
connect(mWheelTimer, &QTimer::timeout, this, [this] {
QTimer::singleShot(0, this, [this] {
if (!QToolTip::isVisible())
Expand Down Expand Up @@ -138,7 +138,10 @@ void VolumePopup::handleSliderValueChanged(int value)
return;
// qDebug("VolumePopup::handleSliderValueChanged: %d\n", value);
m_device->setVolume(value);
QTimer::singleShot(0, this, [this] { QToolTip::showText(QCursor::pos(), m_volumeSlider->toolTip()); });
QTimer::singleShot(0, this, [this] {
if (!mWheelTimer->isActive()) // a wheel event immediately hides the tooltip
QToolTip::showText(QCursor::pos(), m_volumeSlider->toolTip());
});
}

void VolumePopup::handleMuteToggleClicked()
Expand Down Expand Up @@ -220,11 +223,9 @@ void VolumePopup::handleWheelEvent(QWheelEvent *event)
+ (_delta / QWheelEvent::DefaultDeltasPerStep * m_volumeSlider->singleStep()));
_delta = 0;
}
else {
// Since the volume hasn't changed, we need to show the tooltip,
// but only after the wheel rotation is stopped.
mWheelTimer->start();
}

// show the tooltip only after the wheel rotation is stopped
mWheelTimer->start();
}

void VolumePopup::setDevice(AudioDevice *device)
Expand Down

0 comments on commit fbc327a

Please sign in to comment.