11

I have a form written with Qt Designer, which contains a QWidget promoted to a custom widget I have. The custom widget contains several combo boxes. I want the form to have a reasonable tab order, with focus moving from the widget immediately before the custom widget, then going through the combo boxes in the custom widget, and proceeding to the widget after the custom widget. So I set the QWidget to have tab focus in Designer, but the custom widget doesn't handle having focus properly.

I could solve this problem using QWidget::setTabOrder, but that would be messy because I would have to reach into the custom widget from the outside. Alternatively I could give the custom widget a member function to set the tab order. Ideally there should be a simpler way. Is there?

Brian
  • 2,511
  • 20
  • 26
  • Use Edit tab order tool button in Qt designer toolbar – Hesam Qodsi Sep 05 '13 at 17:00
  • @HesamQodsi That doesn't work. If I try to give focus to the custom widget, it doesn't pass the focus through to its children. If there were just one child in the widget that handled focus, I could use QWidget::setFocusProxy with Designer's tab order, but that won't work in this case because there are multiple children in the custom widget that need to take focus. – Brian Sep 05 '13 at 17:12
  • 6
    check setFocusProxy() of your custom widget – Ashif Sep 05 '13 at 17:32
  • 4
    I didn't think using setFocusProxy would work... I figured that would cause the focus to move straight from the previous widget in the dialog, to the widget set as the focus proxy, to the widget after the custom widget. But I tried it anyway and it turns out that using setFocusProxy gives the desired behavior after all. So, thanks, user231502! – Brian Sep 13 '13 at 17:54
  • 2
    @Ashif and Brian: One of you should put this as the answer and Brian should accept it. – Martin Hennings Jul 11 '18 at 07:32
  • 1
    Does this answer your question? [How to redirect parent widget focus to a child widget?](https://stackoverflow.com/questions/57865905/how-to-redirect-parent-widget-focus-to-a-child-widget) – Abderrahmene Rayene Mihoub May 19 '23 at 12:18

0 Answers0