Setting styles in wxWidgets?

Apr 13, 2009 at 10:29pm
I've been using wxWidgets with Python, but wanted to learn C++ while retaining wx. I'm having a problem figuring out how to set styles for wxTextCtrl. I want my text to align from right to left.

In Python all I had to do was this:
wx.TextCtrl(parent, -1, style=wx.ALIGN_RIGHT)

If I do the same in C++:
wxTextCtrl(parent, -1, style=wxALIGN_RIGHT)

I get this error:
error: 'style' was not declared in this scope


How do I accomplish this in C++?
Apr 13, 2009 at 10:51pm
Unfortunately, setting styles is a little funky in wx C++. You can input the style in the ctor, however it's like the 5th or 6th parameter in the list, so you have a type a bunch of other crap too:

1
2
3
4
5
6
7
8
mytextctrl = new wxTextCtrl(
  parent,
  wxID_ANY,
  wxEmptyString,
  wxDefaultPosition,
  wxDefaultSize,
    input_style_here
  );


You can look up wxTextCtrl's ctors for a list of parameters here:

http://docs.wxwidgets.org/stable/wx_wxtextctrl.html#wxtextctrlctor

Although it dawns on me that wxALIGN_RIGHT is not a window style (at least I didn't see it on the list). Did you mean wxTE_RIGHT?
Apr 13, 2009 at 11:49pm
Thank you Disch, that is helpful. I was hoping there was a way to do it without inputting all the other parameters.

I tried using SetStyle, but I couldn't figure out how to set the first two params:
wxTextCtrl->SetStyle(param1, param2, wxALIGN_RIGHT)

The docs say that they are long values, but I'm very new to C++.

I'm not sure where wxALIGN_RIGHT comes from, but it works for wxTextCtrl.
Topic archived. No new replies allowed.