QT day1

复制代码
#include "widget.h"
#include <iostream>
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()
{
}
相关推荐
PPPPickup9 分钟前
金证秋招笔试
java·开发语言
不正经学生26 分钟前
C语言结构体:自定义数据类型,让变量打包出行
java·c语言·开发语言·数据结构·算法
老一岁36 分钟前
c问题总结(1)
c语言·开发语言
程与留1 小时前
06_Qt 常用数据类型与容器:QString、QList、QVector、QMap 的性能与实现分析
数据结构·qt
林森lsjs2 小时前
队列 FIFO 原理 & 手撕两种队列实现(链表 + 循环数组)—数据结构陆
java·开发语言·数据结构·队列
何以解忧,唯有..2 小时前
Python time 模块详解:时间处理与日期操作指南
开发语言·python
caimouse2 小时前
ReactOS 窗口系统分析(20):光标与图标 — cursoricon.c
c语言·开发语言
longxiaozhang63 小时前
C#运算符重载:让对象也能使用“加减乘除”
开发语言·c#
mounter6254 小时前
GCCRS 突破与 Rust 入核:Linux 工具链的重大变革
linux·开发语言·rust·linux kernel·kernel
Buke..4 小时前
【APP 逆向】哔哩哔哩 sign 参数逆向(上):Frida 反调试绕过与 unidbg 调用
java·开发语言·爬虫·python·安卓