2023/09/15 qt day1

代码实现图形化界面

cpp 复制代码
#include "denglu.h"
#include "ui_denglu.h"
#include <QDebug>
#include <QIcon>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
denglu::denglu(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::denglu)
{
    ui->setupUi(this);
    this->setFixedSize(430,360); //设置固定主界面尺寸
    this->setWindowTitle("Widget"); //设置窗口标题
    this->setWindowIcon(QIcon("C:\\Users\\12297\\Desktop\\icon\\wodepeizhenshi.png"));
//    //实例化一个标签
    QLabel *lab1 = new QLabel(this);
    lab1->resize(430,180); //设置占窗体一半尺寸
    lab1->setPixmap(QPixmap("C:\\Users\\12297\\Desktop\\icon\\logo.png"));
    lab1->setScaledContents(1);
    //实例化第二个标签
    QLabel *lab2 = new QLabel(this);
    lab2->resize(45,30);  //设置尺寸
    lab2->move(this->x()+65,this->y()+200); //移动位置
    lab2->setPixmap(QPixmap("C:\\Users\\12297\\Desktop\\icon\\userName.jpg"));//填充图片
    lab2->setScaledContents(1);
    //实例化第三个标签
    QLabel *lab3 = new QLabel(this);
    lab3->resize(45,30);  //设置尺寸
    lab3->move(lab2->x(),lab2->y()+60); //移动位置
    lab3->setPixmap(QPixmap("C:\\Users\\12297\\Desktop\\icon\\passwd.jpg"));//填充图片
    lab3->setScaledContents(1);
    //实例化行编辑器1
    QLineEdit *edit1 = new QLineEdit(this);
    edit1->resize(200,32); //设置尺寸
    edit1->move(lab2->x()+55,lab2->y()); //移动位置
    edit1->setPlaceholderText("admin"); //设置默认值,占位文本
    //实例化行编辑器2
    QLineEdit *edit2 = new QLineEdit(this);
    edit2->resize(200,32); //设置尺寸
    edit2->move(lab3->x()+55,lab3->y()); //移动位置
    edit2->setEchoMode(QLineEdit::Password); //设置回显模式
    edit2->setMaxLength(6); //设置最大文本容量
    //实例化按钮1
    QPushButton *b1 = new QPushButton(QIcon("C:\\Users\\12297\\Desktop\\icon\\login.png"),"登录",this);
    b1->resize(80,32); //设置尺寸
    b1->move(this->x()+100,lab3->y()+50); //移动位置

    //实例化按钮1
     QPushButton *b2 = new QPushButton(QIcon("C:\\Users\\12297\\Desktop\\icon\\cancel.png"),"取消",this);
    b2->resize(80,32); //设置尺寸
    b2->move(this->x()+230,b1->y()); //移动位置











}

denglu::~denglu()
{
    delete ui;
}

效果图

模拟面试问题

相关推荐
新缸中之脑8 小时前
开发AI代理必备的8个Python 库
开发语言·人工智能·python
暴走十八步8 小时前
PHP+vscode开启调试debug
开发语言·vscode·php
郝学胜-神的一滴8 小时前
Python 列表 vs 数组:深入解析与最佳选择指南
开发语言·python·程序人生
杜子不疼.8 小时前
基于ATVC模板库的Ascend C Vector算子快速开发指南
c语言·开发语言·mfc
MSTcheng.8 小时前
【C++】C++11新特性(三)
开发语言·c++·c++11
learning-striving8 小时前
kali连不上网解决方法
linux·开发语言·网络·php·kali
田野追逐星光8 小时前
STL容器list的模拟实现
开发语言·c++·list
StandbyTime8 小时前
《算法笔记》学习记录-第二章 C/C++快速入门
c++·算法笔记
摇滚侠8 小时前
macbook shell 客户端推荐 Electerm macbook 版本下载链接
java·开发语言
我在人间贩卖青春8 小时前
C++之结构体与类
c++··结构体