Qt4: configure which widget will focus on launch

If I do not QMainWindow::showEvent() (which will contain the setFocus () method for this widget), is there any way to let some widget focus first when the window loads? I use the Qt4 form editor, but could not find it anywhere to configure it.

+6
source share
2 answers

You can set the Tab Order in Qt Designer or the Designer component in Qt Creator. The first widget in tab order should focus on loading.

tab order

Many users expect to be able to navigate between widgets and controls using only the keyboard. Qt allows the user to navigate between widget inputs with the Tab and Shift + Tab keyboard shortcuts. The default tab order is based on the order in which widgets are built. Although this order may be sufficient for many users, it is often best to explicitly specify the tab order to make it easier for your application to use.

Tab ordering

To enter the tab order editing mode, open the "Edit" menu and select "Change" Tab order. In this mode, each input widget in the form is displayed using a number indicating its position in tab order. So, if the user gives the first input focus input widget and then presses the tab key, the focus will move to the second input widget, etc.

The order of the tabs is determined by clicking on each of the numbers in the correct order. The first number you click will change to red, indicating the current edited position in the order chain. the widget associated with the number will be the first in the order chain tab. Clicking on another widget will make it second in the order of the tabs, etc.

Repeat this process until you are satisfied with the tab order in the form - you do not need to click each input widget if you see that the other widgets are already in the correct order. The numbers for which you have already set, change to green, and those that have not yet been pressed will remain blue.

If you make a mistake, simply double-click outside of any number or select "Restart" from the context menu of the form to start again. if you have many widgets in your form and would like to change the order of the tabs in the middle or at the end of the order chain on the tab, you can edit it at any position. Press Ctrl and click the number from which you want Start. Alternatively, select "Start from here" in the context menu.

+13
source

I never used the form editor, but you could just call widget views in your code

+9
source

Source: https://habr.com/ru/post/918561/


All Articles