VS2017 Qt 新增Ui界面
1.新增ui文件。
2.增加cpp和头文件。
cpp文件
#include "ui_Welcome.h"
#include"Welcome.h"
Welcome::Welcome(QWidget *parent) :QMainWindow(parent),ui(new Ui::Form)
{
ui->setupUi(this);
}
头文件
#include <QtWidgets/QMainWindow>
#include"ui_Welcome.h"
/*namespace Ui {
class Welcome;
}*/
class Welcome : public QMainWindow
{
Q_OBJECT
public:
Welcome(QWidget *parent = Q_NULLPTR);
//~Welcome();
private:
Ui::Form *ui;
};
ui_*.h
#ifndef UI_WELCOME_H
#define UI_WELCOME_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
QPushButton *pushButton;
QWidget *widget;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout_2;
QLabel *label;
QLineEdit *lineEdit;
QHBoxLayout *horizontalLayout;
QLabel *label_2;
QLineEdit *lineEdit_2;
QPushButton *pushButton_2;
void setupUi(QWidget *Form)
{
if (Form->objectName().isEmpty())
Form->setObjectName(QStringLiteral("Form"));
Form->resize(481, 383);
pushButton = new QPushButton(Form);
pushButton->setObjectName(QStringLiteral("pushButton"));
pushButton->setGeometry(QRect(9, 351, 75, 23));
widget = new QWidget(Form);
widget->setObjectName(QStringLiteral("widget"));
widget->setGeometry(QRect(130, 90, 207, 68));
verticalLayout = new QVBoxLayout(widget);
verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
label = new QLabel(widget);
label->setObjectName(QStringLiteral("label"));
horizontalLayout_2->addWidget(label);
lineEdit = new QLineEdit(widget);
lineEdit->setObjectName(QStringLiteral("lineEdit"));
horizontalLayout_2->addWidget(lineEdit);
verticalLayout->addLayout(horizontalLayout_2);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
label_2 = new QLabel(widget);
label_2->setObjectName(QStringLiteral("label_2"));
horizontalLayout->addWidget(label_2);
lineEdit_2 = new QLineEdit(widget);
lineEdit_2->setObjectName(QStringLiteral("lineEdit_2"));
horizontalLayout->addWidget(lineEdit_2);
verticalLayout->addLayout(horizontalLayout);
pushButton_2 = new QPushButton(Form);
pushButton_2->setObjectName(QStringLiteral("pushButton_2"));
pushButton_2->setGeometry(QRect(410, 350, 61, 23));
retranslateUi(Form);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
Form->setWindowTitle(QApplication::translate("Form", "Form", nullptr));
pushButton->setText(QApplication::translate("Form", "\346\263\250\345\206\214", nullptr));
label->setText(QApplication::translate("Form", "\347\224\250\346\210\267\345\220\215\357\274\232", nullptr));
label_2->setText(QApplication::translate("Form", "\345\257\206\347\240\201\357\274\232", nullptr));
pushButton_2->setText(QApplication::translate("Form", "\347\231\273\345\275\225", nullptr));
} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};//Cpp
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_WELCOME_H