One scrollbar around wcTextCtrl and wxGrid

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
neilsp
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Aug 13, 2017 6:44 pm

One scrollbar around wcTextCtrl and wxGrid

Post by neilsp »

Hi

I suspect that this is an easy question, but I cannot find the answer anywhere.

I currently have a multi-line wxTextCtrl with a variable number of lines of wrapped text, which is positioned above a wxGrid with a few more lines (say 20 or so) of tabular data, with both controls in a vertical wxBoxSizer. This works fairly well and is close to what I'm after, except that there are vertical scroll-bars on both the wxTextCtrl and the wxGrid.

How would I go about getting one vertical scroll-bar that would scroll both the wxTextCtrl and the wxGrid? Basically I would like the block of text above the wxGrid and the WxGrid itself to move as a unit when the vertical scroll bar is moved.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: One scrollbar around wcTextCtrl and wxGrid

Post by doublemax »

Definitely not an easy question ;)

First of all, can you post a screenshot? I don't see how it makes sense to scroll two controls that are on top of each other with one vertical scrollbar. I could understand it, if they were side by side.

However, the problem here is that wxTextCtrl is a native control and wxGrid is not, it will be very hard to make them scroll in parallel.
Use the source, Luke!
neilsp
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Aug 13, 2017 6:44 pm

Re: One scrollbar around wcTextCtrl and wxGrid

Post by neilsp »

Here is a drawing of what I'm after.
Capture.PNG
Capture.PNG (17.22 KiB) Viewed 1710 times
Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: One scrollbar around wcTextCtrl and wxGrid

Post by Nunki »

Hi Neil,

I would strongly advise against that kind of behaviour. An interface should be intuitive and logical. Sliders are introduced with windows. A way to say you page is of size A4 but your window is size A5, so you can only seen 1/2 of your page. That's why your vertcal slider will show a slider size of 50% telling you, you're only seeing half of your page. So basically a slider is fundamentally bound to the window or control in this matter.
It would be different if both control and grid are of fixed, actual size and together they form the content of a window with a vertical slider. That would mean using the slider, it will move you textcontrol out of sight, to show more of the grid.

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

Re: One scrollbar around wcTextCtrl and wxGrid

Post by doublemax »

neilsp wrote:Here is a drawing of what I'm after.
Capture.PNG
Based on that image, i don't see why dragging the scrollbar should also scroll the text control. What kind of information are you displaying in there?

I think you're either building a very unusual (= bad) GUI, or you're using a wxTextCtrl for something it's not made for.
Use the source, Luke!
neilsp
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Aug 13, 2017 6:44 pm

Re: One scrollbar around wcTextCtrl and wxGrid

Post by neilsp »

I must be miss-communicating here, since I am not trying to do any kind of fancy synchronized scrolling of the text and grid controls.

Nunki fairly well described what I'm after:
It would be different if both control and grid are of fixed, actual size and together they form the content of a window with a vertical slider. That would mean using the slider, it will move you textcontrol out of sight, to show more of the grid.
Basically, as shown in my earlier drawing, I just want to show some descriptive text above a table of information and have the whole thing move up and down in a window, when the window it not big enough to show the whole thing at once.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: One scrollbar around wcTextCtrl and wxGrid

Post by doublemax »

Sorry, i totally misunderstood your original question.

But from a GUI point of view it still doesn't make sense to me. If the upper text control is descriptive text, wouldn't it be better if only the wxGrid scrolled its content, so that the descriptive text is visible all the time instead of scrolling out of view?

In any case, if i understand you correctly now, you only need to add one wxScrolledWindow and one wxSizer into the hierarchy to achieve what you want.

Right now you have:

Code: Select all

- wxBoxSizer(wxVERTICAL)
-- wxTextCtrl
-- wxGrid
New:

Code: Select all

- wxBoxSizer(wxVERTIVAL)
-- wxScrolledWindow (new)
--- wxBoxSizer(wxVERTICAL) (new)
---- wxTextCtrl
---- wxGrid
Use the source, Luke!
Post Reply