Hello, I'd like to make the QSlider position set where I clicked with the mouse. As it was suggested here I implemented the proxy style and applied it to my QSlider instance. In my application QSlider is styled with QSS. If I apply the implemented proxy style QSS styling stops working, although I don't change anything related to drawing there.
Here is my slider proxy style implementation:
#include <QProxyStyle>
class SliderProxyStyle : public QProxyStyle
{
public:
explicit SliderProxyStyle
(QStyle *baseStyle
= 0) : QProxyStyle
(baseStyle
) {
}
{
if (hint
== QStyle::SH_Slider_AbsoluteSetButtons) return (Qt::LeftButton | Qt::MidButton | Qt::RightButton);
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
};
#include <QProxyStyle>
class SliderProxyStyle : public QProxyStyle
{
public:
explicit SliderProxyStyle(QStyle *baseStyle = 0) : QProxyStyle(baseStyle)
{
}
int styleHint(QStyle::StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const
{
if (hint == QStyle::SH_Slider_AbsoluteSetButtons)
return (Qt::LeftButton | Qt::MidButton | Qt::RightButton);
return QProxyStyle::styleHint(hint, option, widget, returnData);
}
};
To copy to clipboard, switch view to plain text mode
And this is how I use it:
playbar->setStyle(new SliderProxyStyle(playbar->style()));
QSlider * playbar = new QSlider(Qt::Horizontal);
playbar->setStyle(new SliderProxyStyle(playbar->style()));
To copy to clipboard, switch view to plain text mode
Is it possible to use QProxyStyle along with QSS styling?
Bookmarks