How to change style of scrollbar Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

How to change style of scrollbar

Post by Ellan » Wed Aug 09, 2017 9:27 am

Hello,
I want to change the style of the scroll bar according to my own idea,
Is there any way?
Thanks

Best Regards

Ellan

PB
Part Of The Furniture
Part Of The Furniture
Posts: 3001
Joined: Sun Jan 03, 2010 5:45 pm

Re: How to change style of scrollbar

Post by PB » Wed Aug 09, 2017 11:19 am

AFAIK, there is no support in wxWidgets for customizing scrollbar appearance (aside from being able to retrieve some scrollbar dimensions with wxSystemSettings). You are on your own and must platform specific code.

Liter1936
In need of some credit
In need of some credit
Posts: 1
Joined: Tue Jun 13, 2017 7:17 am

Re: How to change style of scrollbar

Post by Liter1936 » Wed Aug 09, 2017 12:52 pm

so if we platform our own code we're gonna be able to change it? that's super strange... i never thought abotu changing the style of scrollbar, but i was like 95% sure that we can... strange we cannot.

User avatar
doublemax
Moderator
Moderator
Posts: 15943
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to change style of scrollbar

Post by doublemax » Thu Aug 10, 2017 2:22 am

wxWidgets' main philosophy is to use native controls and native look where ever possible. Because of that, changing the native look of controls or even window elements is impossible most of the time.

If you only need a custom scrollbar, one option might be to hide the native scrollbars of a control (if possible depends on the control) and implement your own scrollbar from scratch. That's not a trivial task, especially for a wxWidgets beginner, but it's no rocket science either.
Use the source, Luke!

Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

Re: How to change style of scrollbar

Post by Ellan » Fri Aug 25, 2017 6:57 am

doublemax wrote:wxWidgets' main philosophy is to use native controls and native look where ever possible. Because of that, changing the native look of controls or even window elements is impossible most of the time.

If you only need a custom scrollbar, one option might be to hide the native scrollbars of a control (if possible depends on the control) and implement your own scrollbar from scratch. That's not a trivial task, especially for a wxWidgets beginner, but it's no rocket science either.
I'm sorry that I haven't seen BBS recently, but I just saw your reply. If I want to customize the scroll bar, can you please refer to it? Thank you very much for your guidance.
Thanks

Best Regards

Ellan

User avatar
doublemax
Moderator
Moderator
Posts: 15943
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to change style of scrollbar

Post by doublemax » Fri Aug 25, 2017 11:53 am

Like already mentioned, you usually can't customize the native scrollbar, you'd have to create a custom control that mimics the behavior of a scrollbar. That means:
- draw the background
- draw the arrows
- draw the slider
- react to mouse events to change the position of the slider
- generate events so that the main window can react to changes in the slider

You could use the Universal implementation as a start, it's in <wxdir>/src/univ/scrolbar.cpp
Use the source, Luke!

Ellan
Experienced Solver
Experienced Solver
Posts: 57
Joined: Mon May 15, 2017 10:11 am

Re: How to change style of scrollbar

Post by Ellan » Sat Aug 26, 2017 2:07 am

doublemax wrote:Like already mentioned, you usually can't customize the native scrollbar, you'd have to create a custom control that mimics the behavior of a scrollbar. That means:
- draw the background
- draw the arrows
- draw the slider
- react to mouse events to change the position of the slider
- generate events so that the main window can react to changes in the slider

You could use the Universal implementation as a start, it's in <wxdir>/src/univ/scrolbar.cpp
Thank you very much for your advice!
Thanks

Best Regards

Ellan

mxoliveira73
Experienced Solver
Experienced Solver
Posts: 56
Joined: Sun May 05, 2019 7:12 am

Re: How to change style of scrollbar

Post by mxoliveira73 » Mon Jun 10, 2019 8:56 pm

I'm looking for a simple way to change color of Scrollbar.... someone help me, please?

User avatar
doublemax
Moderator
Moderator
Posts: 15943
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to change style of scrollbar

Post by doublemax » Mon Jun 10, 2019 9:28 pm

mxoliveira73 wrote:
Mon Jun 10, 2019 8:56 pm
I'm looking for a simple way to change color of Scrollbar.... someone help me, please?
Everything in this thread is still valid: There is no way to change the color of a native scrollbar.
Use the source, Luke!

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

Re: How to change style of scrollbar

Post by AmadeusK525 » Tue Apr 13, 2021 11:04 pm

doublemax wrote:
Fri Aug 25, 2017 11:53 am
Like already mentioned, you usually can't customize the native scrollbar, you'd have to create a custom control that mimics the behavior of a scrollbar. That means:
- draw the background
- draw the arrows
- draw the slider
- react to mouse events to change the position of the slider
- generate events so that the main window can react to changes in the slider

You could use the Universal implementation as a start, it's in <wxdir>/src/univ/scrolbar.cpp
Sorry for bringing this up again, but I'd really like some advice. I'm not sure how to actually bind the wxWindow to my custom scrollbar. I derived from wxControl and I've already made it possible to draw the thumbtrack and the bar according to the client and virtual sizes of the target window. But I'm still unsure about a couple of topics.

- How do I actually make it so that the window and the scrollbar have bound events? Do I have to bind them, for example, on the scrollbar's creation and call Skip() on all of them so that the window can handle its own implementations? And when then override DoSetVirtualSize() on the window to always adjust the scrollbar after the fact? (This would mean that the window needs to store a pointer to the scrollbar).

- Where do I store the stats for the current ScrolledPos? GetScrolledPos() doesn't seem to return a valid number (with wxRichTextCtrl it always returns 0, even if I programmatically call Scroll() - which is a function from wxScrolledHelper). If I store these things in the scrollbar class, how do i scroll the target window programmatically? Calling ScrollWindow() doesn't seem to do it (at least with wxRichTextCtrl. Maybe this class, being generic, works in a different way).

- There's no way to embed it into the window, is there? I'll always have to put both of them in the same sizer, but separated from each other, right?

User avatar
doublemax
Moderator
Moderator
Posts: 15943
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to change style of scrollbar

Post by doublemax » Wed Apr 14, 2021 5:41 am

My suggestion went only as far as creating a custom wxScrollBar, a separate control, which would be sufficient if your scrolled window was 100% custrom drawn. You'd only have to handle virtual size and scroll position in the drawing code.

If however, you wanted a complete wxScrollWindow implementation, you'd open a whole new can of worms because of the questions you asked. You'd propably have to create a composite control that consists of a wxWindow and the two custom scrollbars. Just subclassing wxWindow might not work, but i'm not 100% sure about that. And then you'd have to code the logic to bind these two together. Any changes the user makes to the scrollbar need to be redirected to the window and vice versa.

Personally, i can't think of any project that justifies that kind of effort. Depending on your actual task, short cuts might be possible.
Use the source, Luke!

Post Reply