当前位置: 首页 > news >正文

qt作业day2

//widget.cpp#include "widget.h"
#include "ui_widget.h"void Widget::usr_login()
{if("admin" == this->edit_acc->text()){if("123456" == this->edit_psd->text()){speech->say("登录成功");emit jump_sig1();this->hide();}else {speech->say("账号或密码错误");this->edit_psd->clear();}return;}speech->say("账号或密码错误");this->edit_psd->clear();
}Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);//设置窗口标题this->setWindowTitle("第七史诗");//设置窗口iconthis->setWindowIcon(QIcon(":/icon/1.png"));//设置窗口大小this->resize(QSize(500,400));//创建标签,设置图片this->lab_front = new QLabel(this);lab_front->setPixmap(QPixmap(":/icon/logo.png"));lab_front->setScaledContents(true);lab_front->resize(500,200);lab_acc = new QLabel(this);lab_acc->setPixmap(QPixmap(":/icon/userName.jpg"));lab_acc->setScaledContents(true);lab_acc->resize(40,30);lab_acc->move(100,lab_front->y() + lab_front->height() + 30);lab_psd = new QLabel(this);lab_psd->setPixmap(QPixmap(":/icon/passwd.jpg"));lab_psd->resize(lab_acc->size());lab_psd->setScaledContents(true);lab_psd->move(lab_acc->x(),lab_acc->y() + 50);//增加单行编辑器edit_acc = new QLineEdit(this);edit_acc->setPlaceholderText("stove账号/邮箱");cout << lab_acc->width() << endl;edit_acc->move(lab_acc->x() + lab_acc->width() + 50,lab_acc->y());edit_psd = new QLineEdit(this);edit_psd->setPlaceholderText("密码");edit_psd->move(edit_acc->x(),edit_acc->y() + 50);//设置输入内容隐藏edit_psd->setEchoMode(QLineEdit :: Password);//登录按钮btn_login = new QPushButton("登录",this);btn_login->setIcon(QIcon(":/icon/login.png"));btn_login->move(300,edit_psd->y() + edit_psd->height() + 30);//取消按钮btn_cancel = new QPushButton("取消",this);btn_cancel->setIcon(QIcon(":/icon/cancel.png"));btn_cancel->move(btn_login->x() + btn_login->width() + 10,btn_login->y());//设置语音播报speech = new QTextToSpeech(this);server = new QComboBox(this);server->addItem("日本服务器");server->addItem("韩国服务器");server->addItem("国际服务器");server->move(50,btn_cancel->y());connect(btn_cancel,&QPushButton :: clicked,this,&Widget :: close);connect(btn_login,&QPushButton :: clicked,this,&Widget :: usr_login);}Widget::~Widget()
{delete ui;
}
//widget.h#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QSize>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QComboBox>
#include <iostream>
#include <QString>
#include <QDebug>
#include <QTextToSpeech>
#include <windows.h>using namespace std;namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:
signals:void my_signal();void jump_sig1();
public slots:void usr_login();public:explicit Widget(QWidget *parent = nullptr);~Widget();private:Ui::Widget *ui;QLabel *lab_front,*lab_acc,*lab_psd;QLineEdit *edit_acc,*edit_psd;QPushButton *btn_login,*btn_cancel;QComboBox *server;QTextToSpeech *speech;};//void Widget :: jump_sig1()
//{
//    this->hide();
//}#endif // WIDGET_H
//form.h#ifndef FORM_H
#define FORM_H#include <QWidget>
#include "widget.h"
namespace Ui {
class Form;
}class Form : public QWidget
{Q_OBJECTpublic slots:void jump_slot();public:explicit Form(QWidget *parent = nullptr);~Form();private:Ui::Form *ui;QPushButton *return_key;
};#endif // FORM_H
//form.cpp#include "form.h"
#include "ui_form.h"void Form::jump_slot()
{this->show();
}Form::Form(QWidget *parent) :QWidget(parent),ui(new Ui::Form)
{ui->setupUi(this);this->resize(QSize(800,700));return_key = new QPushButton(this);return_key->resize(80,70);QPixmap icon1(":/icon/return.png");icon1.scaled(return_key->size());//    QLabel *lab = new QLabel(this);
//    lab->setPixmap(icon1);return_key->setIcon(icon1);return_key->setStyleSheet("background-image:url(:/icon/return.png)");return_key->move(300,200);}Form::~Form()
{delete ui;
}
//main.cpp#include "widget.h"
#include <QApplication>
#include "form.h"int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();Form f;//f.show();QObject :: connect(&w,&Widget :: jump_sig1,&f,&Form :: jump_slot);return a.exec();
}

运行效果

登录成功后跳转from界面

http://www.lryc.cn/news/159555.html

相关文章:

  • JWT一篇通
  • 【2023-09-01】vue中自定义按钮设置disabled属性后,异常触发click事件
  • nginx报错file not found解决
  • 【力扣】96. 不同的二叉搜索树 <动态规划>
  • Win11搭建 Elasticsearch 7 集群(一)
  • 哭了,python自动化办公,终于支持 Mac下载了
  • 【已更新建模代码】2023数学建模国赛B题matlab代码--多波束测线问题
  • GMSL技术让汽车数据传输更为高效(转)
  • ARM+Codesys标准通用型控制器
  • YOLOV8从零搭建一套目标检测系统(修改model结构必看)附一份工业缺陷检测数据集
  • Maven 的其它插件
  • 系列十三、Java操作RocketMQ之带Key的消息
  • C#调用Dapper
  • 2023高教杯数学建模1:ABC题目+初步想法
  • ApachePulsar原理解析与应用实践(学习笔记一)
  • 2023开学礼《乡村振兴战略下传统村落文化旅游设计》许少辉八一新书南京财经大学图书馆
  • qt 信号与槽机制,登录界面跳转
  • uniapp的两个跳转方式
  • 【LeetCode】1654:到家的最少跳跃次数的解题思路 关于力扣无法return的BUG的讨论
  • Calico IP In IP模拟组网
  • 在linux上挂载windows共享目录
  • drone的简单使用
  • day 52 | 84.柱状图中最大的矩形
  • BUUCTF刷题十一道(08)
  • 快速构建基于Paddle Serving部署的Paddle Detection目标检测Docker镜像
  • SOLIDWORKS工程图自动零件序号的极致体验
  • 将ROS bag转成CSV
  • jframe生成柱状图片+图片垂直合并+钉钉机器人推送
  • 如何用J-Link仿真PY32F003系列芯片
  • # Go学习-Day10