PDA

View Full Version : Setting colour on qslider



sanjeet
11th March 2016, 13:16
Hi,

I Am trying to set colour for half of slider which is vertical,but I Am not able to do.

Can you please suggest how to do????

Thanks in Advance......

ChrisW67
12th March 2016, 11:39
You mean something like a red upper half and a green lower half?

sanjeet
17th March 2016, 04:52
Exactly....but I want to set only lowerhalf with red colour....

ChrisW67
18th March 2016, 12:33
You can fake it with the border image:


#include <QApplication>
#include <QSlider>

int main(int argc, char **argv)
{
QApplication app(argc, argv);

QSlider slider(Qt::Vertical);
slider.resize(40, 300);
slider.setStyleSheet(" QSlider { border-image: url('bg.png') 0 0 0 0 stretch stretch; } " );
slider.show();
return app.exec();
}

with a file bg.png that is an 18x18 pixel square with a transparent upper half, and coloured lower half.
11799