tab, taborder and default (enter) features


11-02-2011 19:47:42


Before I go simply do this in code, could someone confirm if there is an existing system for handling 'tabbing between widgets' and default action when enter is pressed.
If there is, then how do I turn it on and control the tab order.

Here is a quick example.

I have a window with two text fields and a button. (logon page)
the user clicks in the username field and types in the username. Here, if the user hits tab I need the focus to move to the next field, password.
In the password field, if the user hits enter I need it to trigger the button press event.

I know this is relatively straightforward to implement in code, just want to make sure its not already implemented and just needs turning on.


12-02-2011 00:47:24

It is not implemented neither in MyGUI nor in MyGUI's demos or tools.


01-03-2011 20:06:20

Thanks Altren. Thats great. Just wanted to check before I implemented it manually.

For anyone else asking this question, it is very easy to implement something along these lines manually.

my example is based on username/password Edit widgets, and then a 'Login' button.
on my Edit widgets you just need to set the ->eventKeyButtonPressed property with a delegate as normal. (MyGUI::newDelegate())

here is a tiny snippet of my code illustrating what happens in my delegate functions.

void game_login::txtUsername_KeyButtonPressed(MyGUI::Widget* _sender, MyGUI::KeyCode _key, MyGUI::Char _char) {
if(_key==MyGUI::KeyCode::Tab) {
void game_login::txtPassword_KeyButtonPressed(MyGUI::Widget* _sender, MyGUI::KeyCode _key, MyGUI::Char _char) {
if(_key==MyGUI::KeyCode::Return) {

I know its simple enough to figure out but it took me (pretty noobish) a while to work out the names and locations of some things such as setKeyFocusWidget.
Hopefully this will save someone a bit of time.



01-03-2011 23:12:21

Hi James,

I've been working on the same kind of thing and ended up writing a patch that might be of interest:


The difference in approach is that with the above patch you can set a single delegate at the root widget for your hierarchy for your chosen key combination (ie. Tab) and have it work no matter where the focus currently is. The downside of course is that being an unofficial patch you'd need to be comfortable maintaining your own tweaked version of MyGUI. :} (this isn't an issue for me as I already need to do this for other reasons)

Either way, I just thought I'd mention it, because even if you didn't use it, it might be of interest to you.


21-03-2011 18:14:28

Many thanks Garthy,

For the time being I just implemented what I needed using the keyboard events but when I have finished the job I have right now I will take a look at that.

Many thanks for posting it. Much appreciated.


21-03-2011 22:30:34

Not a problem. :)

Personally, if you've got a working solution, I'd stick with that. But if you find yourself making changes to the MyGUI code itself, it could be worth a quick experiment. :)