QT day1

#include "widget.h"
#include 
using namespace std;
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //输出大小
    qDebug() << "size=" << this->size(); //输出尺寸大小
    this->resize(540,410); //重新设置尺寸大小
    this->resize(QSize(540,410)); //使用匿名对象,调用重新设置尺寸函数
    qDebug() << "size=" << this->size();
    qDebug() << "width=" << this->width(); //输出组件的宽度
    qDebug() << "height=" << this->height(); //获取高度

    //设置尺寸最值
    this->setMaximumSize(1000,800); //最大尺寸
    this->setMinimumSize(200,100); //最小尺寸
    this->setFixedSize(540,410);  //固定尺寸

    //窗口标题
    qDebug() << this->windowTitle();
    this->setWindowTitle("Kunicq");
    qDebug() << this->windowTitle();

    //设置窗口的icon
    this->setWindowIcon(QIcon("C:/Users/ws/Desktop/windowIcon.png"));

    //设置背景色,一般使用样式表完成
    this->setStyleSheet("background-color:white;");

    //设置窗口透明度
    this->setWindowOpacity(1);

    //设置纯净窗口
    //this->setWindowFlag(Qt::FramelessWindowHint);

    //移动窗口位置
    //this->move();

    //添加按钮组件
    QPushButton *btn1 = new QPushButton;
    //btn1->show();

    //给按钮指针父组件,让其依附于界面存在
    btn1->setParent(this);  //给组件指定父组件,让其依附于界面存在
    btn1->setText("登录");  //给按钮设置文本内容
    qDebug() << "按钮大小=" << btn1->size(); //界面大小
    btn1->resize(360,45); //设置按钮组件的大小
    btn1->move(90,340); //移动组件位置
    btn1->setStyleSheet("background-color:skyblue;"
                        //"border-radius:10px;"
                        "color:white;"); //设置样式表

    //构造一个按钮时,指定父组件
    QPushButton *btn2 = new QPushButton(this); //将当前界面设置为父组件
    btn2->setText("注册账号");
    btn2->resize(60,35);
    btn2->move(0,375);
    btn2->setWindowOpacity(0); //透明度
    //btn2->setEnabled(false); //设置为不可用状态
    //btn2->setIcon(QIcon());  //设置图标

    //构造按钮时,给定文本内容以及父组件
    QPushButton *btn3 = new QPushButton("找回密码",this);
    btn3->resize(60,20);
    btn3->move(390,300);
    btn3->setWindowOpacity(0);

    //构造一个按钮,构造时给定父组件、文本内容、icon
    //QPushButton btn4 = new QPushButton(QIcon(),"",this);

    //构造一个行编辑器,构造时给定父组件
    QLineEdit *edit1 = new QLineEdit(this);
    //edit1->setText("账号"); //设置编辑器中的文本内容
    edit1->setPlaceholderText("QQ/手机/邮箱"); //设置编辑器的占位文本
    edit1->resize(310,40); //设置尺寸
    edit1->move(140,200); //移动位置
    edit1->setMaxLength(12);
    //edit1->setEnabled(false) //设置不可用状态

    //构造一个行编辑器,构造时给定父组件以及文本内容
    QLineEdit *edit2 = new QLineEdit("",this);
    //qDebug() << edit2->text(); //获取行编辑器中文本内容
    edit2->setPlaceholderText("密码");
    edit2->resize(edit1->size());
    edit2->move(140,250);
    edit2->setMaxLength(16);
    edit2->setEchoMode(QLineEdit::Password); //设置回显模式

    //实例化一个标签
    QLabel *lab1 = new QLabel("账户",this);
    lab1->resize(40,40);
    lab1->setStyleSheet("background-color:skyblue");
    lab1->setPixmap(QPixmap("C:/Users/ws/Desktop/windowIcon.png"));
    lab1->setScaledContents(true); //设置内容自适应
    lab1->move(90,200);

    //实例化一个标签
    QLabel *lab2 = new QLabel("密码",this);
    lab2->resize(40,40);
    lab2->setStyleSheet("background-color:skyblue");
    lab2->setPixmap(QPixmap("C:/Users/ws/Desktop/icon/passwd.jpg"));
    lab2->setScaledContents(true);
    lab2->move(90,250);

    //实例化一个标签
    QLabel *lab3 = new QLabel("",this);
    lab3->resize(540,195);
    lab3->setPixmap(QPixmap("C:/Users/ws/Desktop/icon/kun.jpg"));
    lab3->setScaledContents(true);

    //实例化一个
    QCheckBox *cb1 = new QCheckBox("自动登录",this);
    cb1->resize(90,20);
    cb1->move(100,300);

    //实例化一个
    QCheckBox *cb2 = new QCheckBox("记住密码",this);
    cb2->resize(90,20);
    cb2->move(250,300);
}

Widget::~Widget()
{
}

QT day1_第1张图片

你可能感兴趣的:(qt,开发语言)