wxTextCtrl doesn't Scroll Horizontally When text is longer than the Width of wxTextCtrl itself

24 views
Skip to first unread message

Jason Liam

unread,
Aug 22, 2021, 4:22:04 AM8/22/21
to wx-u...@googlegroups.com
I have a wxTextCtrl of a certain "fixed" width and height. Now when the text inside the textctrl is longer/wider than the width of the textctrl itself then there is no horizontal scrolling of the text as some users(including me) would expect. For example this is how i create the textctrl:
input_TextCtrl = new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxSize(350, 30), wxTE_READONLY);

Now when i append some text into the textctrl lets say "This is a very long sample text that has a width greater than that of the corresponding textctrl". Now usually when the text is too large(width-wise) to be fully contained in the textctrl, we can scroll horizontally to see the whole content of the textctrl. But in this case there is no horizontal scrolling. I tried using the styles "wxHSCROLL" and "wxTE_DONTWRAP" separately but that also doesn't make horizontal scrolling work. Is there a way to achieve this in wxWidgets? Also, shouldn't this be the default behaviour for single line textctrls? I am using wxWidgets 3.1.5 on Ubuntu 18.04 x86_64.

Gunter Königsmann

unread,
Aug 22, 2021, 6:05:11 AM8/22/21
to wx-u...@googlegroups.com, Jason Liam
Does the same happen if you remove the read-only attribute?

Jason Liam

unread,
Aug 22, 2021, 6:10:30 AM8/22/21
to Gunter Königsmann, wx-u...@googlegroups.com
Yes, even if i remove the read-only attribute then also there is no horizontal scrolling for very long text.

Vadim Zeitlin

unread,
Aug 22, 2021, 8:00:14 AM8/22/21
to wx-u...@googlegroups.com
On Sun, 22 Aug 2021 13:51:51 +0530 Jason Liam wrote:

JL> I have a wxTextCtrl of a certain "fixed" width and height. Now when the
JL> text inside the textctrl is longer/wider than the width of the textctrl
JL> itself then there is no horizontal scrolling of the text as some
JL> users(including me) would expect. For example this is how i create the
JL> textctrl:
JL> input_TextCtrl = new wxTextCtrl(this, wxID_ANY, "",
JL> wxDefaultPosition, wxSize(350, 30), wxTE_READONLY);

This is unrelated to your question, but you really shouldn't use
hard-coded values in pixels for the size. Instead, use something based on
the character width (which takes the current font size and DPI into
account) for the width and leave the height as -1 to use the default value.

JL> Now when i append some text into the textctrl lets say "*This is a very
JL> long sample text that has a width greater than that of the corresponding
JL> textctrl*". Now usually when the text is too large(width-wise) to be fully
JL> contained in the textctrl, we can scroll horizontally to see the whole
JL> content of the textctrl. But in this case there is no horizontal scrolling.

No platform I know of ever shows horizontal scrollbar for the single-line
text controls. However you can, of course, scroll in it by using the cursor
keys, e.g. pressing End will go to the end of your long string and scroll
the text if it doesn't fit into the control entirely.

If you absolutely need a scrollbar, you must use a multiline control.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Jason Liam

unread,
Aug 22, 2021, 9:09:10 AM8/22/21
to wx-u...@googlegroups.com
@VZ I think you misunderstood what/which effect i was talking about so for reference i have attached an mp4 video file that shows the effect that i am talking about. Also, whether I use a hardcoded value or a sizer for the textctrl's size isn't relevant here. Whenever the text becomes too long to fit inside the textctrl it should automatically be able to scroll as shown in the attached video. I guess this feature isn't there in wxWidgets(or is it?). And maybe that's why the misunderstanding. So if this isn't already available in wxWidgets, I guess this is a feature request from my side.
PS: The effect is shown at around the end of the 30 second long video.
textCtrl_HorizontalScrolling.mp4

Igor Korot

unread,
Aug 22, 2021, 9:28:43 AM8/22/21
to wx-u...@googlegroups.com
Hi, Jason,


On Sun, Aug 22, 2021, 08:09 Jason Liam <jlam...@gmail.com> wrote:
@VZ I think you misunderstood what/which effect i was talking about so for reference i have attached an mp4 video file that shows the effect that i am talking about. Also, whether I use a hardcoded value or a sizer for the textctrl's size isn't relevant here. Whenever the text becomes too long to fit inside the textctrl it should automatically be able to scroll as shown in the attached video. I guess this feature isn't there in wxWidgets(or is it?). And maybe that's why the misunderstanding. So if this isn't already available in wxWidgets, I guess this is a feature request from my side.
PS: The effect is shown at around the end of the 30 second long video.

I'm not sure what you are talking about. 
According to your own video the text scrolls horizontally just fine.

What did you expect?

Thank you.

--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/CA%2BuK%3DSAzjnw-26AJO2iNU%2BSnXuHQU5TSFFVYJNt%3DLJnvYvCONw%40mail.gmail.com.

Jason Liam

unread,
Aug 22, 2021, 9:42:40 AM8/22/21
to wx-u...@googlegroups.com
@Igor The video shows the effect that is not available in the wxTextCtrl that i created. That is, the video shows the effect that I want but is not there in the wxTextCtrl(or is it?). I made the video on Tor browser just as an example since i already had it opened. Is the same scrolling behavior available in wxWidgets' wxTextCtrl, that is when the text gets too long the text should be horizontally scrollable?

Gunter Königsmann

unread,
Aug 22, 2021, 10:40:10 AM8/22/21
to wx-u...@googlegroups.com, Jason Liam
On wxGtk scrolling text horizontally works. On Windows scrolling should work if the control has the keyboard focus...

Igor Korot

unread,
Aug 22, 2021, 11:03:06 AM8/22/21
to wx-u...@googlegroups.com, Jason Liam
Hi, Jason,



On Sun, Aug 22, 2021, 09:40 Gunter Königsmann <gunter.ko...@gmail.com> wrote:
On wxGtk scrolling text horizontally works. On Windows scrolling should work if the control has the keyboard focus...

Are you trying to scroll with the mouse or keyboard?

Thank you.

--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.

Vadim Zeitlin

unread,
Aug 22, 2021, 3:11:17 PM8/22/21
to wx-u...@googlegroups.com
On Sun, 22 Aug 2021 18:38:48 +0530 Jason Liam wrote:

JL> @VZ I think you misunderstood what/which effect i was talking about so for
JL> reference i have attached an mp4 video file that shows the effect that i am
JL> talking about.

This works just fine for me in a simple single line text control when
using wxGTK, i.e. typing at the end does scroll it so that the current
caret position remains always visible. You can try it in the "text" sample,
for example. If it really doesn't work for you, you need to understand what
are you doing differently.

JL> Also, whether I use a hardcoded value or a sizer for the
JL> textctrl's size isn't relevant here.

This is perhaps why I wrote that it was unrelated to your question. But
it's still a bad idea to do it.

Jason Liam

unread,
Aug 23, 2021, 12:46:05 AM8/23/21
to wx-u...@googlegroups.com
@VZ There are two distinct effects when the text gets too long:
1) Effect 1 The one which you described above. Typing at the end does scroll it so that the current caret position remains always visible. This works in my case also as expected.
2) Effect 2 When the text gets too long then  we can use the TRACKPAD of the laptop to scroll horizontally(left and right). This is shown in the first video that I uploaded(of TOR Browser textctrl). Note that this 2nd effect does not happen using a mouse and only happens using a trackpad.
My question is that why doesn't this 2nd effect happen in wxWidgets' wxTextCtrl using a TRACKPAD ? I have tried the text sample provided in samples directory and there also in single line textctrl there is no horizontal scrolling using trackpad.
Can you confirm that this 2nd effect is intentionally not there in wxWidgets' wxTextCtrl(probably because wxWidgets use native behavior)?

PS: I think that this 2nd effect is not natively supported and therefore it is also not there in wxWidgets. For example, whenever I try to do this in any of the web browsers or any other web based technology using trackpad then this effect is supported but when I try to do this in the search bar of the OS that i am running(Ubuntu for example) using trackpad then this effect is not supported. Can this feature be added to wxWidgets' wxTextCtrl in future versions or to maintain native behavior there is no plan for this?

Vadim Zeitlin

unread,
Aug 23, 2021, 7:58:16 AM8/23/21
to wx-u...@googlegroups.com
On Mon, 23 Aug 2021 10:15:51 +0530 Jason Liam wrote:

JL> @VZ There are two distinct effects when the text gets too long:
JL> 1) *Effect 1 *The one which you described above. Typing at the end does
JL> scroll it so that the current caret position remains always visible. This
JL> works in my case also as expected.
JL> 2) *Effect 2 *When the text gets too long then we can use the *TRACKPAD *of
JL> the laptop to scroll horizontally(left and right). This is shown in the
JL> first video that I uploaded(of TOR Browser textctrl). Note that this 2nd
JL> effect
JL> *does not happen using a mouse and only happens using a trackpad. *
JL> My question is that why doesn't this 2nd effect happen in wxWidgets'
JL> wxTextCtrl using a *TRACKPAD ? *I have tried the text sample provided in
JL> samples directory and there also in single line textctrl there is no
JL> horizontal scrolling using trackpad.
JL> Can you confirm that this 2nd effect is intentionally not there in
JL> wxWidgets' wxTextCtrl(probably because wxWidgets use native behavior)?

Yes. I can't scroll using trackpad in native GtkEntries in other GTK
applications neither.

JL> PS: I think that this 2nd effect is not natively supported and therefore it
JL> is also not there in wxWidgets. For example, whenever I try to do this in
JL> any of the web browsers or any other web based technology using trackpad
JL> then this effect is supported but when I try to do this in the search bar
JL> of the OS that i am running(Ubuntu for example) using trackpad then this
JL> effect is not supported. Can this feature be added to wxWidgets' wxTextCtrl
JL> in future versions or to maintain native behavior there is no plan for
JL> this?

No, there are no plans to do it. Personally this doesn't seem like a very
useful feature to me: usually single line text controls not fitting their
contents should be avoided, so it should be quite rare to have them in the
first place and I don't really know who will even think to use trackpad
scrolling to scroll in them. I admit I had never even though to do it until
now myself.

Jason Liam

unread,
Aug 23, 2021, 8:30:17 AM8/23/21
to wx-u...@googlegroups.com
I agree that this "scrolling feature using trackpad" might not be so popular yet. It's just that I use it regularly(since I mostly use laptops and that too without mouse) and so thought that most other people are aware of this. But it doesn't seem to be the case. Thanks anyways.
Reply all
Reply to author
Forward
0 new messages