ui->setupUi(this);//虽然关联了 但子控件的布局不会随着窗口大小发生改变
this->setLayout(ui->verticalLayout);//设置最大的布局
关于布局如上
设置窗口标题
this->setWindowTitle("heell");
this->setFixedSize(600,1200);//设置固定大小
this->resize(400,800);
关于按钮的一些操作
QPushButton * btn = new QPushButton(this);
指定父对象 父对象释放时子对象也会释放
btn->resize(50,60);设置按钮大小
btn->setText("sdsdsdsds");设置按钮的文本
QFont a("宋体",20,10,1); //字体对象
btn->setFont(a); //设置字体
btn->setStyleSheet("QPushButton{backgroud-color: red;}"); //设置样式表
btn->move(100,200); 移动按钮的位置
btn->show();
qt中调式输出
qDebug()<<"sss";
对象树:Qt中的类的继承关系,在一定程度上简化了对象释放操作,由Qt中的QObject类派生出来的,该类无需首当释放内存,添加到QObject或QObject派生类的对象,也无需手动释放,程序结束后,Qt会自动检测对象树的对象,释放对象先释放子对象从一层一层的最终释放完毕
今日小作业:
具体代码如下:
this->setFixedSize(400,500);
this->setWindowTitle("测试窗口");
QPushButton * btn = new QPushButton(this);
btn->resize(150,200);
btn->setText("HELLOQT");
QFont a("华文行楷",20,10,1);
btn->setFont(a);
btn->setStyleSheet("QPushButton:hover{background-color:red;}\
QPushButton:pressed{background-color:blue;}");
演示效果如下:
鼠标放上变红色
点击后变蓝色
作业2:在qt中设置三个按钮,文本为 max min normal,为三个按钮绑定点击信号当依次点击时 窗口设置为最大化 最小化 正常
1 在头文件中设置私有成员变量
QPushButton *max;
QPushButton * min;
QPushButton*normal;
设置槽函数:
public slots:
void onmaxclicked();
void onminclicked();
void onnormalclicked();
窗口类中实现槽函数:
void MainWindow::onmaxclicked()
{
showMaximized(); //Qt中槽函数自带的显示窗口
}
void MainWindow::onminclicked()
{
showMinimized();
}
void MainWindow::onnormalclicked()
{
showNormal();
}
对按钮实例化并进行信号连接
max = new QPushButton("max",this);
min = new QPushButton("min",this);
normal = new QPushButton("normal",this);
max->move(50,50);min->move(50,100);normal->move(50,150);
**************************信号连接如下
max = new QPushButton("max",this);
min = new QPushButton("min",this);
normal = new QPushButton("normal",this);