概括:
1.创建QPushButton * btn = new QPushButton;
2.设置父亲setParent(this);
3.设置按钮文字btn->setText("wenzi")
4.移动控件move(x, y)
5.重置尺寸resize(w, h)
6.设置窗口标题setWindowText("title")
7.设置窗口固定尺寸setFixedSize(w, h)
注意:工具-选项-文本编辑器-行为-编码要设置为utf-8,否则显示可能会乱码
注意:qss书写一定要符合规范,否则会报错
一、创建QPushButton
上节代码中,我们发现,QWidget.show()之后可显示窗口,我们尝试用这种办法显示QPushButton
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>//引入QPushButton类
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) //初始化列表,该函数的声明中已有默认值
, ui(new Ui::MainWindow)
{
//新建按钮
QPushButton* btn = new QPushButton;
//显示
btn->show();
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}