QTday2

本文详细描述了如何在C++中使用Qt框架创建一个包含标签、动画、文本输入框、按钮和菜单栏的基本图形用户界面程序。
摘要由CSDN通过智能技术生成

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    //设置背景颜色
    this->setStyleSheet("background-color:rgb(255,250,250)");
    //重新设置窗口大小
    this->resize(600,600);
    //固定窗口大小
    this->setFixedSize(800,800);
    
    //创建一个标签
    QLabel *l1 = new QLabel;
    l1->setParent(this);
    l1->resize(800,500);
    
    //设置动图
    QMovie *mv=new QMovie("C:\\Users\\10110\\Desktop\\pictrue\\82a8d3fd16b153d6.gif");
    mv->setParent(this);
    l1->setMovie(mv);
    mv->start();
    l1->setScaledContents(true);
    
    //设置标签二
    QLabel *l2=new QLabel("账户",this);
    l2->setStyleSheet("background-color:rgb(3,187,250)");
    l2->move(250,600);
    l2->resize(70,50);
    //设置标签三
    QLabel *l3=new QLabel("密码",this);
    l3->setStyleSheet("background-color:rgb(3,187,250)");
    l3->move(250,660);
    l3->resize(70,50);
    //设置行编译器一  输入账户
    QLineEdit *e2 = new QLineEdit(this);
    e2->setStyleSheet("background-color:rgb(250,250,250)");
    e2->move(320,600);
    e2->resize(130,50);
    //设置行编译器二   输入密码
    QLineEdit *e1 =new QLineEdit(this);
    e1->setEchoMode(QLineEdit::Password);
    e1->setStyleSheet("background-color:rgb(250,250,250)");
    e1->move(320,660);
    e1->resize(130,50);

    //实例化一个按钮
    QPushButton *btn1 =new QPushButton;
    btn1->setParent(this);
    btn1->setText("寻找鸡哥");
    btn1->setStyleSheet("background-color:rgb(3,187,250)");
    btn1->resize(130,50);
    btn1->move(320,730);
    
    //设置菜单栏
    QMenuBar *mb = menuBar();
    this->setMenuBar(mb);
    QMenu *file = mb->addMenu("文件");
    file->addAction("新建");
    file->addSeparator();
    file->addAction("打开");
    //设置工具栏
    QToolBar *tbar=new QToolBar(this);
    this->addToolBar(Qt::LeftToolBarArea,tbar);
    tbar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
    tbar->setFloatable(false);
    tbar->addAction("欢迎");
    QPushButton *btn = new QPushButton(this);
    btn->setText("编写");
    tbar->addWidget(btn);



}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值