Changing the (default) circular tab order into a linear one
I have already posted the problem at stockoverflow if you want to read about others comments: How to break the tab order chain of widgets in Qt?
My application uses the tab order to navigate through the GUI by pressing keys. I pretty much can control how the tab order (the chain of selectable widgets) is configured and it works but the chain is always closed so that the user can come back to the first widget after the last one.
So, for example, I have 4 widgets they are connected like this: A - B - C - D - (back to A)
This means that I can go to D by going back from A and I can go to A by going forward from D. I would like to stay at A so that I can only go forward to B and I want to stay at D so I can only go backwards to C.
The setTabOrder() does not allow to link a widget to itself so one solution is to insert dummy-objects that redirect the focus. The problem is that my GUI is built dynamically so, for example:
StartDummy - A - B - C - D - EndDummy
This works as long as D is inside my chain. If I hide() the widget D the connection to the EndDummy breaks and Qt closes the tab order automatically. This way the user can still go around the widgets.
Do you have any other suggestions? Is there a way to listen to focus events and ignore them? Even if this would work I had the problem that my widgets have to know if they are the last or first one.
I have another idea now. What if i reimplement bool QWidget::focusNextPrevChild(bool next)? According to the docu one can use this to implement custom focus behavior.
Do anyone have experience with this?
In my dynamic scenario where buttons in the GUI are adjusted at runtime I will have to overload the function and set, for example, flag "allowFocusNext" and "allowFoxusPrev" which then ignores the focus request if necessary. I will report back here, when I have tried it.
Just a thought.
If you disable default tab order handling.
Then build you own list and then onKeyPress just select next from list and in case
you add / remove elements , update the list.
Then it would not round trip or do anything besides what you make it.
thanks for the comment. I thought about a custom list too but although this would work, it is a huge effort to integrate it in an existing application with many screens and widgets where some of them are created dynamically.
I have found a working solution by overriding void wheelEvent(QWheelEvent* event) but I'm not happy with it. I posted my solution here.
I'm still looking for better ideas! :-)