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()
{
}
相关推荐
侃侃_天下2 天前
最终的信号类
开发语言·c++·算法
echoarts2 天前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix2 天前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题2 天前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说2 天前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔2 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
我是菜鸟0713号2 天前
Qt 中 OPC UA 通讯实战
开发语言·qt
JCBP_2 天前
QT(4)
开发语言·汇编·c++·qt·算法
Brookty2 天前
【JavaEE】线程安全-内存可见性、指令全排序
java·开发语言·后端·java-ee·线程安全·内存可见性·指令重排序
百锦再2 天前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame