Qt学习 第7节:模仿QT写代码

#ifndef UI_Window
#define UI_Window

#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>

#include <QtWidgets/QLabel>

class Ui_Window
{
public:
    QMenuBar *menuBar;
    QToolBar *mainToolBar;
    QWidget *centralWidget;
    QStatusBar *statusBar;
    QLabel* label;//模范他,加label控件

    void setupUi(QMainWindow* p2User_Window)
    {
        if (p2User_Window->objectName().isEmpty())
            p2User_Window->setObjectName(QStringLiteral("p2User_Window"));
        p2User_Window->resize(400, 300);
        menuBar = new QMenuBar(p2User_Window);
        menuBar->setObjectName(QStringLiteral("menuBar"));
        p2User_Window->setMenuBar(menuBar);
        mainToolBar = new QToolBar(p2User_Window);
        mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
        p2User_Window->addToolBar(mainToolBar);
        centralWidget = new QWidget(p2User_Window);
        centralWidget->setObjectName(QStringLiteral("centralWidget"));
        p2User_Window->setCentralWidget(centralWidget);
        statusBar = new QStatusBar(p2User_Window);
        statusBar->setObjectName(QStringLiteral("statusBar"));
        p2User_Window->setStatusBar(statusBar);

        label = new QLabel("Hello Qt",centralWidget);//label控件设置为Hello Qt,父窗口是centralWidget

        retranslateUi(p2User_Window);

        QMetaObject::connectSlotsByName(p2User_Window);
    }// setupUi

    void retranslateUi(QMainWindow *p2User_Window)
    {
        p2User_Window->setWindowTitle(QApplication::translate("p2User_Window", "p2User_Window", 0));
    } // retranslateUi
};
#endif // UI_Window

#ifndef USER_WINDOW_H
#define USER_WINDOW_H

#include <QMainWindow>
#include "Ui_Window.h"

class User_Window : public QMainWindow
{
    Q_OBJECT

private:
    Ui_Window *ui;

public:
    User_Window(QWidget *parent = 0);
    ~User_Window();
};

#endif // USER_WINDOW_H
#include "User_Window.h"

User_Window::User_Window(QWidget *parent) : QMainWindow(parent)
{
    ui = new Ui_Window;
    ui->setupUi(this);
}

User_Window::~User_Window()
{
    delete ui;
}
#include "User_Window.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    User_Window w;
    w.show();

    return app.exec();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值