Joe C
Joe C

Reputation: 2827

Set focus to the first widget

I have a dialog with tabs, and each tab has some check blocks and input blocks.

I think if I do not set any focus order, the order is defined in terms of the order in which those widgets are added. I am fine with the initial order.

After users tab and change focus, I wanted to reset the focus back to the first widget. Because the widget tree is constructed top-down in my case, I think I can traverse children of each widget node to find the first widget.

Is there a better way to do? Will children be stored in the order they are added?

Upvotes: 1

Views: 1129

Answers (1)

cbuchart
cbuchart

Reputation: 11575

You can use the QWidget::nextInFocusChain method to retrieve the first widget that must receive the focus.

Upvotes: 1

Related Questions