views:

339

answers:

3

I'm using a small black and white screen and need the scrollbar to just be a black slider in a black outer frame. I got what I wanted using style sheets but including them in the configuration when installing takes up too much space so I can't use them. Is it possible to remove the arrows by inheriting from QStyle or something? thanks

A: 

This might be a dumb answer but would it help if you just specified the style sheet itself in code as a QString argument to setStyleSheet rather than maintain a separate file for it?

Troubadour
To use setStyleSheet Qt would still need to be configured to include the stylesheet stuff which I can't do.
Mark
Ah okay, I didn't realise you meant Qt configuration. In fact I didn't even realise they were a configuration option in QT... ;)
Troubadour
A: 

You can try to change palette settings for your scroll bar (according to designer scroll bar arrow color is "button text" color), but this approach looks lick little hack... More "heavy" approach, is inherit from scroll bar widget and reimplement paint method, but there are it is looks like overkill...
So, you must choose little hack vs overkill :). Though maybe there are exist another solution

vnm
+1  A: 

You should create a subclass of a QStyle (or some subclass like QCommonStyle) and reimplement its drawComplexControl() function to paint CC_ScrollBar element by yourself.

Read QStyle's documentation for more.

dpimka
An alternative on the same lines is to inherit and override the sizes of the elements of the complex control, so that the size for the arrows is empty, and the size for the scroll bar portion is expanded to fill where the arrows would have been. Then let the style draw the components itself.
Caleb Huitt - cjhuitt
Oh, nice solution indeed. If this would work out, this is way simpler than reimplementing draw functions :)
dpimka
Thanks you two, I got it working with your help. I ended up having to calculate where the slider should be drawn (in drawcontrol) after it was scaled up in length, based on its original position when the arrows were there. As far as I could find it wasn't possible to alter the size of the elements of the complex control, that would have been nice though.
Mark
I think that should be QStyle::subControlRect() - make it return an empty (or perhaps some other special crafted) QRect for QStyle::SC_ScrollBarAddLine and QStyle::SC_ScrollBarSubLine sub controls.Though I didn't try it - but judging from apidox this could work :)Anyway, great you've found a solution :)
dpimka