Qt第一个Qt程序

Qt第一个窗口程序

1.创建项目

2.创建按钮

修改mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPushButton *btn = new QPushButton("按钮", this);
    // 重新指定窗口大小
    this->resize(600, 400);

    // 设置窗口标题
    this->setWindowTitle("第一个项目");

    // 限制窗口大小
    this->setFixedSize(600, 400);
    // 设置父亲
    btn->setParent(this);
    // 设置文字
    btn->setText("按钮1");
    // 移动位置
    btn->move(100, 100);
}

MainWindow::~MainWindow()
{
    delete ui;
}

posted @ 2023-02-17 12:42  对CSDN使用炎拳吧  阅读(14)  评论(0编辑  收藏  举报