Skinnable scrollbars

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
bertolino
Experienced Solver
Experienced Solver
Posts: 62
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Skinnable scrollbars

Post by bertolino » Sat Apr 17, 2021 8:13 pm

Hello everyone,

I've noticed that regularly, wxWidgets users are looking for a way to change their scrollbar style.
Last year I started something about this, then the time passed, I forgot this piece of code until recently
where I came across one of these articles. So I decided to share what I did in the case it could help (see example below).

Image

It's not a miracle solution, it's not production-ready code, I even do not claim it's a good solution.
But it may help people as a base to do something better.

It is based on the wxScrolled<wxWindow>::SetTargetWindow that is able to redirect scrolling to a given window.

The code is reasonably commented so I guess it can be handled and modified without too much difficulties.
I have tested it under Windows only, using wxWidgets 3.1.

You will find a zip archive of it here http://www.gipsa-lab.grenoble-inp.fr/~p ... dow_v2.zip that includes:
- 1 file for the toy program
- 2 files (cpp and .h) for the scrolled window class
- 2 files (cpp and .h) for the scrollbar class

my_scrolled_window.h explains with a small graphic the way the panels are embedded in each other.

In the main file, a #define among 5 allows to see the scrolled window in different contexts :
- to scroll a panel
- to scroll a toolbar (in this case, horizontal or vertical scroll can be disabled)
- to scroll a dialog

One can tune:
- the scroll direction (horizontal, vertical or both)
- the thumb color, the margin color and the tip color (not sure it's the right terms)
- the size of these items

All the events are not managed but the thumbs work well with the mouse. it still needs some work....
I hope you will enjoy it.

By the way, thanks to the wxWidgets team for such a great tool and thank you to the forum team for their valuable support all year long.

Kind regard,

Pascal

AmadeusK525
Knows some wx things
Knows some wx things
Posts: 49
Joined: Wed Aug 19, 2020 12:04 am

Re: Skinnable scrollbars

Post by AmadeusK525 » Tue May 04, 2021 12:58 am

This is a nice solution to it! A lot of people have wanted a way to customize the scrollbars, so I think this is a very good contribution :)
I've made a custom solution to this as well, but it works in a different way and it's restricted to wxRichTextCtrl. Interesting to see how different your method of implementation was compared to mine.

Post Reply