LaurentY
LaurentY

Reputation: 7653

How to set min width on GtkScrollbar?

I want to develop new features in Quod Libet music player.

I need to increase size of specific scrollbar. There's a function already exists to apply css to a widget:

def add_css(widget, css):
    """Add css for the widget, overriding the theme.

    Can raise GLib.GError in case the css is invalid
    """

    if not isinstance(css, bytes):
        css = css.encode("utf-8")

    provider = Gtk.CssProvider()
    provider.load_from_data(css)
    context = widget.get_style_context()
    context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

So I try to apply css as this:

    self.scrollwin = sw = ScrolledWindow()
    sw.set_shadow_type(Gtk.ShadowType.IN)
    #get scrollbar       
    vscrollbar = sw.get_vscrollbar()

    # 1rst attempt
    # qltk.add_css(vscrollbar, '* slider {min-width: 20px;}')

    #2nd attempt
    qltk.add_css(vscrollbar, 'scrollbar.vertical slider {min-width: 20px;}')

I've got same error with 2 attempts:

'min-width' is not a valid property name (3)

Update 1

I try @Herbalist solution, scrollbar component is resized but "slider" always have same size. It add spaces on right and on left of "slider".

vscrollbar.set_size_request(50,-1)

Is it possible to resize slider of scrollbar ?

Screenshot of result (I outline part of scrollbar in green): enter image description here

Upvotes: 1

Views: 1473

Answers (2)

LaurentY
LaurentY

Reputation: 7653

I'm not able to success with css, so I use deprecated method:

GtkRange:slider-width has been deprecated since version 3.20 and should not be used in newly-written code.

Use the min-height/min-width CSS properties on the slider element. The value of this style property is ignored.

As this:

qltk.add_css(vscrollbar, '* {-GtkRange-slider-width:40px}')

Upvotes: 3

user7628061
user7628061

Reputation:

get_vscrollbar() returns a Gtk.Widget so you could try setting the "width-request" property

Upvotes: -1

Related Questions