1.思维导体
2.作业
#include "widget.h"Widget::Widget(QWidget *parent): QWidget(parent)
{qDebug()<<this->size();qDebug()<<this->rect().size();qDebug()<<this->geometry().size();qDebug()<<this->frameGeometry().size();qDebug()<<"width:"<<this->width()<<" height:"<<this->height();qDebug()<<"width:"<<this->size().width()<<" height:"<<this->size().height();//设置固定尺寸this->setFixedSize(500,400);//关于窗口标题qDebug()<<this->windowTitle(); //获取窗口标题this->setWindowTitle("靓仔轻聊"); //设置窗口标题//设置窗口图标this->setWindowIcon(QIcon("C:\\Users\\Administrator\\Desktop\\2023725184913.bmp"));//设置背景色//this->setStyleSheet("background-color:orange;");//设置透明度this->setWindowOpacity(0.9);//设置标签QLabel *lab1=new QLabel; //设置父组件lab1->setParent(this); //设置父组件lab1->resize(500,100); //重新设置尺寸lab1->setAlignment(Qt::AlignCenter); //垂直和水平全部居中lab1->setPixmap(QPixmap("C:\\Users\\Administrator\\Desktop\\2023725191221.bmp")); //设置标签位图片lab1->setScaledContents(true); //内容自适应//lab1->setStyleSheet("background-color:blue");QLabel *lab2 =new QLabel(this);lab2->resize(50,50);lab2->move(100,130);lab2->setPixmap(QPixmap("C:\\Users\\Administrator\\Desktop\\2023725192425.bmp")); //设置标签位图片lab2->setScaledContents(true); //内容自适应//lab2->setStyleSheet("background-color:blue");QLabel *lab3=new QLabel(this);lab3->resize(50,50);lab3->move(100,200);lab3->setPixmap(QPixmap("C:\\Users\\Administrator\\Desktop\\2023725193242.bmp")); //设置标签位图片lab3->setScaledContents(true); //内容自适应QLineEdit *edit1=new QLineEdit;edit1->setParent(this); //设置父组件edit1->resize(230,50); //重新设置尺寸edit1->move(150,130); //移动edit1->setPlaceholderText(":用户名/账号"); //设置占位符edit1->setStyleSheet("border:none;""border-bottom:2px solid black;");QLineEdit *edit2=new QLineEdit(this);//edit2->setParent;edit2->resize(230,50);edit2->move(150,200);edit2->setEchoMode(QLineEdit::Password); //设置密文模式edit2->setPlaceholderText(":密码"); //设置占位符edit2->setStyleSheet("border:none;""border-bottom:2px solid black;");QPushButton *btn1=new QPushButton(this);btn1->setText("登录"); //设置按钮上的文本内容qDebug()<<btn1->text(); //获得按钮上的文本内容btn1->resize(80,50); //重新设置按钮的大小qDebug()<<btn1->size();btn1->move(150,300); //移动组件btn1->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\2023725203342.bmp")); //设置按钮图标QPushButton *btn2=new QPushButton(this);btn2->setText("取消"); //设置按钮上的文本内容qDebug()<<btn2->text(); //获得按钮上的文本内容btn2->resize(80,50); //重新设置按钮的大小qDebug()<<btn2->size();btn2->move(300,300);btn2->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\2023725203754.bmp")); //设置按钮图标}Widget::~Widget()
{
}
效果图: