Promlems with setStyleSheet
Hi to all,
I'm doing some test with the style sheet. I'm trying to customize a QSlider.
I create a class inherited from QFrame containing just a QSlider so:
Code:
#ifndef __VOLWIDGET_H__
#define __VOLWIDGET_H__
#include <QFrame>
#include <QSlider>
class VolWidget
: public QFrame{
Q_OBJECT
public:
virtual ~VolWidget();
signals:
void sig_volChanged(int);
protected:
private:
};
#endif // __VOLWIDGET_H__
After creating the QSlider in the ctor I would apply to it a style using the setStyleSheet routine.
Code:
VolWidget
::VolWidget( QWidget* parent
){
setStyleSheet(" QSlider::groove:vertical { \
background: red; \
position: absolute; \
left: 4px; \
right: 4px; }\
QSlider::handle:vertical { \
height: 10px; \
background: green; \
margin: 0 -4px; /* expand outside the groove */ } \
QSlider::add-page:vertical { \
background: white; } \
QSlider::sub-page:vertical { \
background: pink; }");
m_volSlider
= new QSlider(Qt
::Horizontal);
m_volSlider->setMinimum( 0 );
m_volSlider->setMaximum( 100 );
m_volSlider->setValue( 100 );
vLayout->setContentsMargins(0, 0, 0, 0);
vLayout->addWidget(m_volSlider);
setLayout(vLayout);
connect(m_volSlider, SIGNAL( valueChanged(int) ), this, SIGNAL( sig_volChanged(int) ) );
}
In my case the code has no effect. No style sheet is applied to the QSlider.
Where I'm wrong?
Regards
Re: Promlems with setStyleSheet
Your code is correct, the reason you not able to see the style sheet applied is...
You are setting style for QSlider::groove:vertical, QSlider::handle:vertical, QSlider::add-page:vertical and QSlider::sub-page:vertical, all these are vertical components; and you are adding a new QSlider(Qt::Horizontal), which uses horizontal components
so either change you style to horizontal, or change QSlider to vertical:cool: