实现一个页面切换功能
1.新建一个无ui界面的工程,其基类为dialog
2.代码实现
dialog.h
添加QTabWidget头文件
#include
<QTabWidget>
Dialog类中进行私有控件声明
private:
QTabWidget
* tabWidget
;
dialog.cpp
#include
"dialog.h"
#include
<QLineEdit>
#include
<QPushButton>
#include
<QLabel>
Dialog
::Dialog(QWidget
*parent
)
: QDialog(parent
)
{
tabWidget
= new QTabWidget(this);
QWidget
* widget
= new QWidget();
QLineEdit
* lineEdit
= new QLineEdit(widget
);
lineEdit
->setGeometry(10,10,190,30);
QPushButton
* pushButton
= new QPushButton("TEXT",widget
);
pushButton
->setGeometry(10,45,190,30);
QLabel
* label
= new QLabel("你好鸭!");
label
->setAlignment(Qt
::AlignHCenter
|Qt
::AlignVCenter
);
QPushButton
* pushButton3
= new QPushButton("点我呀");
tabWidget
->addTab(widget
,"第一页");
tabWidget
->addTab(label
,"第二页");
tabWidget
->addTab(pushButton3
,"第三页");
tabWidget
->setGeometry(0,0,230,150);
this->resize(230,150);
this->setWindowTitle("切换页面");
}
Dialog
::~Dialog()
{
}
3.效果展示
4.不足
很多
转载请注明原文地址: https://win8.8miu.com/read-4864.html