Insert widget into Qt tabwidget

1. Brief introduction

QT->tabWidget: tab page.
Customize the pull control through the toolbar in the ui, where tabwidget can create multiple tab pages, and two tab_widgets (tab_1/tab_2) are generated by default. And you can freely add tabs such as control deletion by right-clicking in the UI. Switching tabs is to switch widgets.

2. Customized use

If you want to use tabwidget more flexibly, or decouple the page. Then a solution that comes to mind is to separate the ui-widget from the tabwidget and insert the widget through the tabwidget function method.

2.1 Add controls

Interface settings, drag the control into the window and delete the default two tabs

2.2 Custom widgets

Customize the page you want to put in the tabwidget (custom ui-widget)

2.3 Add widget to tab_widget

Add custom ui-widget to tab through the method in tabwidget class

m_userWidget = new UserWidget(this);
ui->tabWidget->addTab(m_userWidget, QString("个人信息"));

3. Effect display

3.1 mainWidget inserts the control tab_widget and deletes the default tab

Insert image description here

3.2 Custom ui-widget

userwidget

3.3 The effect after executing step 2.3 to add tabs

Insert image description here

4. Functions and help documents

tabwidget class function
Help documentation

Guess you like

Origin blog.csdn.net/only_a_Heroic_car/article/details/132074667