Qt QPushButton创建

QPushButton头文件:#include<QPushButton>

 

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

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QPushButton *btn =new QPushButton;
//    btn->show();//show以顶层方式弹出窗口控件

    //让btn对象依赖在mainwindow窗口中
    btn->setParent(this);

    //设置按钮大小
    btn->resize(120,50);

    //显示文本
    btn->setText("第一个按钮");

    //创建第二个按钮 按照控件的大小创建窗口
    QPushButton *btn2=new QPushButton("第二个按钮",this);

    //移动btn2按钮
    btn2->move(100,100);//移动到(100,100)位置

    //设置窗口标题
    setWindowTitle("窗口");

    //设置窗口大小
    resize(600,400);
    
    
    //设置固定窗口大小
    setFixedSize(600,400);//不能缩放

}

MainWindow::~MainWindow()
{
}

 

 

 

posted @ 2020-12-19 09:18  sxkio  阅读(244)  评论(0编辑  收藏  举报