Unsolved "background-color" stylesheet option reject previous drawing results
-
Hi all.
I want to have QSlider with some background text. I derive my widget from QSlider and override paintEvent() to draw an text in this way:
void My::paintEvent(QPaintEvent *ev) { QPainter p(this); style()->drawItemText(&p, rect(), Qt::AlignCenter, palette(), true, tr("FOO")); QStyleOptionSlider opt; initStyleOption(&opt); opt.subControls = QStyle::SC_SliderHandle; style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this); }
In this case I see my drawed text in center of widget. But when the handle position is over the text, the text is blocked by the handle (as text is under the handle), it is ok.
Further, I want to make the handle semi-translucent that my text wasn't blocked by the handle, and stays visible through the handle.
For this purpose I use styleshhet for handle:app.setStyleSheet( " QSlider::handle:horizontal { background-color: rgba(50, 100, 200, 100); width: 13px; } \n" );
All fine, now I see my text through handle.
BUT, when I try to setup widget's background color, using stylesheet option:
app.setStyleSheet( " QSlider { background-color: yellow; } \n" " QSlider::handle:horizontal { background-color: rgba(50, 100, 200, 100); width: 13px; } \n" );
then I do not see my text anymore.
So, what I doing wrong? How to draw my text on "layer" between of the background and the handle? Or, maybe I need other way?
-
@kuzulis
draw the text after you draw the slider ;) -
draw the text after you draw the slider ;)
No, it is not option for me. I need the handle (and groove) at top of text. :(
-
@kuzulis
sorry but how is this supposed to look like?! This doesn't make much sense? -
This doesn't make much sense?
My slider will have own tick-marks with values, which are placed inside of slider widget. Also there (inside of widget) will be placed some additional info (e.g. legends, captions and so forth). It is required by design! So, I need to draw all this stuff on "background"... :(
I use QSlider as base widget, because I want to use its existing "hover" and "groove" stylesheet's properties as need for me (such trick).