Skip to content

Instantly share code, notes, and snippets.

@MasterAler
Created November 1, 2018 12:32
Show Gist options
  • Save MasterAler/d889153726c56899b847b8505e5b7838 to your computer and use it in GitHub Desktop.
Save MasterAler/d889153726c56899b847b8505e5b7838 to your computer and use it in GitHub Desktop.
SliderProxyStyle
#pragma once
#include <QProxyStyle>
/*!
* \brief The SliderProxyStyle class
* This proxy style adds "mouse direct jump" to QSlider, i.e.
* QSlider with this style receives the ability to have it's value set
* by clicking on the desired position.
* Source: https://stackoverflow.com/questions/11132597/qslider-mouse-direct-jump
*
* Usage: mySlider.setStyle(new SliderProxyStyle(mySlider->style()));
*/
class SliderProxyStyle : public QProxyStyle
{
public:
using QProxyStyle::QProxyStyle;
int styleHint(QStyle::StyleHint hint, const QStyleOption* option = nullptr
, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const
{
if (hint == QStyle::SH_Slider_AbsoluteSetButtons)
return (Qt::LeftButton | Qt::MidButton | Qt::RightButton);
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment