QT--3

embedded/2024/10/18 18:15:52/

 Qt

1>将文本编辑器完整实现

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);this->resize(800,600);edit1 = new QTextEdit(this);edit1->resize(600,600);//字体btnziti = new QPushButton("字体",this);btnziti->resize(150,50);btnziti->move(625,50);//颜色btncolor = new QPushButton("颜色",this);btncolor->resize(150,50);btncolor->move(625,125);//打开文件btnopen = new QPushButton("打开文件",this);btnopen->resize(150,50);btnopen->move(625,200);//保存文件btnsave = new QPushButton("保存文件",this);btnsave->resize(150,50);btnsave->move(625,275);connect(btnziti,&QPushButton::clicked,[=](){bool ok = false;QFont f = QFontDialog::getFont(&ok,QFont("宋体",10,10,true),this,"选择字体");if(ok){edit1->setCurrentFont(f);}});connect(btncolor,&QPushButton::clicked,[=](){QColor c = QColorDialog::getColor(QColor("red"),this,"选择颜色");if(c.isValid() == true){edit1->setTextBackgroundColor(c);}});connect(btnopen,&QPushButton::clicked,this,&Widget::openfile);connect(btnsave,&QPushButton::clicked,this,&Widget::savefile);
}Widget::~Widget()
{delete ui;
}void Widget::openfile()
{QString filename = QFileDialog::getOpenFileName(this,"选择文件","./","all(*.*)");QFile file(filename);if(file.open(QFile::ReadOnly)==false){QMessageBox::information(this,"提示","文件打开失败");return;}QByteArray msg = file.readAll();edit1->setText(msg);file.close();
}void Widget::savefile()
{QString filename = QFileDialog::getOpenFileName(this,"选择文件","./","all(*.*)");QFile file(filename);if(file.open(QFile::WriteOnly)==false){QMessageBox::information(this,"提示","文件打开失败");return;}QString msg = edit1->toPlainText();file.write(msg.toUtf8().data());file.close();
}

2>重新将登录框实现完整

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent)
{//=======窗口相关设置======this->resize(680,520);this->setFixedSize(680,520);this->setWindowTitle("Tim");this->setWindowFlag(Qt::FramelessWindowHint);this->setStyleSheet("background-color:rgb(255,255,255)");//=======标签相关设置======QLabel *lab1 = new QLabel(this);lab1->resize(400,520);lab1->setPixmap(QPixmap(":/pictrue/tim.png"));//=======行编辑器相关设置=======edit1 = new QLineEdit(this);edit1->resize(220,50);edit1->move(430,270-50);edit1->setPlaceholderText("QQ号码/手机号/邮箱");edit2 = new QLineEdit(this);edit2->resize(220,50);edit2->move(430,270);edit2->setPlaceholderText("密码");edit2->setEchoMode(QLineEdit::Password);//=======按钮相关设置=====QPushButton *btn1 = new QPushButton(this);btn1->resize(64,64);btn1->move(500-32,120-32);btn1->setStyleSheet("background-color:rgb(17,145,255);border-radius:32px");btn1->setIcon(QIcon(":\\pictrue\\qie.png"));QPushButton *btn2 = new QPushButton(this);btn2->resize(64,64);btn2->move(580-32,120-32);btn2->setStyleSheet("background-color:rgb(245,245,245);border-radius:32px");btn2->setIcon(QIcon(":\\pictrue\\wechat.png"));QPushButton *btn3 = new QPushButton("记住密码",this);btn3->resize(74,25);btn3->move(430,440);btn3->setIcon(QIcon(":\\pictrue\\kuang.png"));QPushButton *btn4 = new QPushButton("自动登陆",this);btn4->resize(74,25);btn4->move(430,470);btn4->setIcon(QIcon(":\\pictrue\\kuang.png"));QPushButton *btn5 = new QPushButton("找回密码",this);btn5->resize(74,25);btn5->move(600,440);QPushButton *btn6 = new QPushButton("注册密码",this);btn6->resize(74,25);btn6->move(600,470);btn7 = new QPushButton(this);btn7->resize(25,25);btn7->move(640,12);btn7->setIcon(QIcon(":\\pictrue\\x.png"));QPushButton *btn8 = new QPushButton(this);btn8->resize(25,25);btn8->move(605,12);btn8->setIcon(QIcon(":\\pictrue\\set.png"));btn9 = new QPushButton("登录",this);btn9->resize(220,50);btn9->move(430,270+80);//   btn9->setStyleSheet("background-color:red;border-radius:5px");connect(edit1, &QLineEdit::textChanged, this, &Widget::mySlots);connect(edit2, &QLineEdit::textChanged, this, &Widget::mySlots);connect(btn7, &QPushButton::clicked, this, &Widget::clicked);connect(btn9, &QPushButton::clicked, [&](){if(edit1->text()=="123456"&&edit2->text()=="123456"){int res = QMessageBox::information(this,"登录","登录成功",QMessageBox::Ok,QMessageBox::Ok);if(res == QMessageBox::Ok){emit jump();this->close();}
//                    qDebug() << "denglu" ;
//                    emit jump();
//                    this->close();}else{QMessageBox box(QMessageBox::Critical,"问题","登录失败,是否重新登录",QMessageBox::Ok|QMessageBox::No,this);box.setButtonText(QMessageBox::No,"no");box.setButtonText(QMessageBox::Ok,"yes");int res = box.exec();if(res == QMessageBox::Ok){edit1->clear();edit2->clear();}else if(res == QMessageBox::No){this->close();}}});
}
Widget::~Widget()
{delete ui;
}
void Widget::clicked()
{QMessageBox box(QMessageBox::Question,"问题","您是否确认退出登录",QMessageBox::Ok|QMessageBox::No,this);box.setButtonText(QMessageBox::No,"no");box.setButtonText(QMessageBox::Ok,"yes");int res = box.exec();if(res == QMessageBox::Ok){this->close();}else if(res == QMessageBox::No){}}
void Widget::mySlots()
{if(edit1->text().size()>=6&&edit2->text().size()>=6){btn9->setEnabled(true);
//        btn9->setStyleSheet("background-color:green;border-radius:5px");}else{btn9->setEnabled(false);
//        btn9->setStyleSheet("background-color:red;border-radius:5px");}
}
#include "second.h"
#include "ui_second.h"void Second::fun()
{this->show();
}Second::Second(QWidget *parent) :QWidget(parent),ui(new Ui::Second)
{ui->setupUi(this);
}Second::~Second()
{delete ui;
}

 

 


http://www.ppmy.cn/embedded/39850.html

相关文章

力扣每日一题115:不同的子序列

题目 困难 给你两个字符串 s 和 t &#xff0c;统计并返回在 s 的 子序列 中 t 出现的个数&#xff0c;结果需要对 109 7 取模。 示例 1&#xff1a; 输入&#xff1a;s "rabbbit", t "rabbit" 输出&#xff1a;3 解释&#xff1a; 如下所示, 有 3 种…

java设计模式 桥接

桥接模式&#xff08;Bridge Pattern&#xff09;是软件工程中的一种设计模式&#xff0c;它将抽象部分与它的实现部分分离&#xff0c;使它们可以独立变化。这种类型的设计模式属于结构型模式&#xff0c;它通过提供抽象化和实现化之间的桥接结构&#xff0c;来实现二者的解耦…

动手学深度学习16 Pytorch神经网络基础

动手学深度学习16 Pytorch神经网络基础 1. 模型构造2. 参数管理1. state_dict()2. normal_() zeros_()3. xavier初始化共享参数的好处 3. 自定义层4. 读写文件net.eval() 评估模式 QA 1. 模型构造 定义隐藏层–模型结构定义前向函数–模型结构的调用 import torch from torch…

HTML【常用的标签】、CSS【选择器】

day45 HTML 继day44&#xff0c;w3cschool 常用的标签 k) 表格 表格由 table 标签来定义。每个表格均有若干行&#xff08;由 tr 标签定义&#xff09;&#xff0c;每行被分割为若干单元格&#xff08;由 标签定义&#xff09;。字母 td指表格数据&#xff08;table data&…

推荐全网最全的AI小白进阶指南

1. 引言 您想学习人工智能&#xff1f;但不知道如何开始&#xff0c;也不知道从哪里开始&#xff1f;互联网上的资源总是丰富多彩&#xff0c;质量参差不齐&#xff0c;往往容易看花眼而无从下手。 鉴于此&#xff0c;本文重点推荐一些个人收集的还不错的一些资源供大家学习参…

网络安全专业岗位详解+自学学习路线图

很多网安专业同学一到毕业就开始迷茫&#xff0c;不知道自己能去做哪些行业&#xff1f;其实网络安全岗位还是蛮多的&#xff0c;下面我会介绍一些网络安全岗位&#xff0c;大家可以根据自身能力与喜好决定放哪个方向发展。 渗透测试/Web安全工程师 主要是模拟黑客攻击&#…

gpt_academic的使用——含一键安装和接入其他API以及本地模型

https://github.com/binary-husky/gpt_academic/releases/ https://github.com/binary-husky/gpt_academic/wiki 安装

2016-2021年全国范围的2.5m分辨率的建筑屋顶数据

一、论文介绍 摘要&#xff1a;大规模且多年的建筑屋顶面积&#xff08;BRA&#xff09;地图对于解决政策决策和可持续发展至关重要。此外&#xff0c;作为人类活动的细粒度指标&#xff0c;BRA可以为城市规划和能源模型提供帮助&#xff0c;为人类福祉带来好处。然而&#xf…