QT记事本+登陆界面的简单实现

主体头文件

#ifndef JSB_H
#define JSB_H#include <QMainWindow>
#include <QMenuBar>//菜单栏
#include <QToolBar>//工具栏
#include <QStatusBar>//状态栏
#include <QTextEdit>//文本
#include <QLabel>//标签
#include <QDebug>//打印
#include <QDateTime>//获取当前时间
#include <QDesktopServices>//桌面服务
#include <QUrl>//资源定位
#include "ipv.h"
#include <QFileDialog>//文件对话框
#include <QColorDialog>//颜色对话框
#include <QFontDialog>//字体对话框
#include <QTextStream>//文本流
#include <QMessageBox>
#include <QCloseEvent>
#include <QDebug>
class JSB : public QMainWindow
{Q_OBJECTpublic:JSB(QWidget *parent = nullptr);~JSB();public slots:void open_slot();void new_slot();void save_slot();void exit_slot();void copy_slot();void patse_slot();void cut_slot();void redo_slot();void undo_slot();void time_slot();void color_slot();void font_slot();void about_slot();void web_slot();void ipv_slot();void closeEvent(QCloseEvent *event);private://菜单栏QMenuBar * bar=NULL;//文件菜单QMenu *File = NULL;//打开QAction *Open = NULL;//新建QAction *New = NULL;//保存QAction *Save = NULL;//退出QAction *Exit = NULL;//编辑菜单QMenu *Edit = NULL;//恢复QAction *Redo = NULL;//撤销QAction *Undo = NULL;//复制QAction *Copy = NULL;//粘贴QAction *Patse = NULL;//剪切QAction *Cut = NULL;//工具菜单QMenu * Tool = NULL;//时间QAction *Time = NULL;//格式菜单QMenu * ForMat = NULL;//颜色QAction *Color = NULL;//字体QAction *Font = NULL;//帮助QMenu *Help = NULL;//关于QAction *About = NULL;//官网QAction *Web = NULL;//版本QAction *IPv = NULL;//工具栏QToolBar *ToolBar = NULL;//状态栏QStatusBar *staBar = NULL;//文本QTextEdit *edit = NULL;};
#endif // JSB_H

主体的函数实现

#include "jsb.h"JSB::JSB(QWidget *parent): QMainWindow(parent)
{//设置窗口大小this->resize(600,600);//设置窗口文本this->setWindowTitle("记事本");//设置窗口图标this->setWindowIcon(QIcon(":/image/Jsb.png"));//初始化菜单this->bar = menuBar();//指定父类bar->setParent(this);//将菜单栏放入到窗口setMenuBar(bar);//创建文件菜单this->File = bar->addMenu("文件(&F)");//菜单项this->New = File->addAction("新建");//快捷键this->New->setShortcut(tr("Ctrl+N"));//分隔符this->File->addSeparator();//新建图标this->New->setIcon(QIcon(":/image/New.png"));connect(New,&QAction::triggered,this,&JSB::new_slot);this->Open = File->addAction("打开");//打开快捷键this->Open->setShortcut(tr("Ctrl+O"));//图标this->Open->setIcon(QIcon(":/image/Open.png"));connect(Open,&QAction::triggered,this,&JSB::open_slot);this->Save = File->addAction("保存");this->Save->setShortcut(tr("Ctrl+S"));this->Save->setIcon(QIcon(":/image/Save.png"));connect(Save,&QAction::triggered,this,&JSB::save_slot);//分隔符this->File->addSeparator();this->Exit = File->addAction("退出");this->Exit->setShortcut(tr("Ctrl+Q"));this->Exit->setIcon(QIcon(":/image/Exit.png"));connect(Exit,&QAction::triggered,this,&JSB::exit_slot);//创建编辑菜单this->Edit = bar->addMenu("编辑(&E)");this->Redo = Edit->addAction("恢复");this->Redo->setShortcut(tr("Ctrl+R"));this->Redo->setIcon(QIcon(":/image/Redo.png"));connect(Redo,&QAction::triggered,this,&JSB::redo_slot);this->Undo = Edit->addAction("撤销");this->Undo->setShortcut(tr("Ctrl+U"));this->Undo->setIcon(QIcon(":/image/Undo.png"));//分隔符this->Edit->addSeparator();connect(Undo,&QAction::triggered,this,&JSB::undo_slot);this->Copy = Edit->addAction("复制");this->Copy->setShortcut(tr("Ctrl+C"));this->Copy->setIcon(QIcon(":/image/Copy.png"));connect(Copy,&QAction::triggered,this,&JSB::copy_slot);this->Patse = Edit->addAction("粘贴");this->Patse->setShortcut(tr("Ctrl+V"));this->Patse->setIcon(QIcon(":/image/Paste.png"));connect(Patse,&QAction::triggered,this,&JSB::patse_slot);this->Cut = Edit->addAction("剪切");this->Cut->setShortcut(tr("Ctrl+X"));this->Cut->setIcon(QIcon(":/image/Cut.png"));connect(Cut,&QAction::triggered,this,&JSB::cut_slot);//创建工具菜单this->Tool = bar->addMenu("工具(&T)");this->Time = Tool->addAction("时间");this->Time->setShortcut(tr("Ctrl+A"));this->Time->setIcon(QIcon(":/image/time.png"));connect(Time,&QAction::triggered,this,&JSB::time_slot);//创建格式菜单this->ForMat = bar->addMenu("格式(&M)");this->Color = ForMat->addAction("颜色");this->Color->setShortcut(tr("Ctrl+Alt+C"));this->Color->setIcon(QIcon(":/image/Color (5).png"));connect(Color,&QAction::triggered,this,&JSB::color_slot);this->Font = ForMat->addAction("字体");this->Font->setShortcut(tr("Ctrl+Alt+F"));this->Font->setIcon(QIcon(":/image/Font (2).png"));connect(Font,&QAction::triggered,this,&JSB::font_slot);//创建帮助菜单this->Help = bar->addMenu("帮助(&H)");this->About = Help->addAction("关于");this->About->setShortcut(tr("Ctrl+Shift+A"));this->About->setIcon(QIcon(":/image/About.png"));this->Web = Help->addAction("官网");this->Web->setShortcut(tr("Ctrl+Shift+W"));this->Web->setIcon(QIcon(":/image/web.png"));connect(Web,&QAction::triggered,this,&JSB::web_slot);this->IPv = Help->addAction("版本");this->IPv->setShortcut(tr("Ctrl+Shift+I"));this->IPv->setIcon(QIcon(":/image/Window.png"));connect(IPv,&QAction::triggered,this,&JSB::ipv_slot);//工具栏this->ToolBar = new QToolBar;this->ToolBar->setParent(this);addToolBar(ToolBar);this->ToolBar->setMovable(false);this->ToolBar->addAction(Open);this->ToolBar->addAction(Exit);this->ToolBar->addSeparator();this->ToolBar->addAction(Redo);this->ToolBar->addAction(Undo);this->ToolBar->addSeparator();this->ToolBar->addAction(Color);this->ToolBar->addAction(Font);this->ToolBar->addSeparator();this->ToolBar->addAction(Web);this->ToolBar->addAction(IPv);//状态栏this->staBar = statusBar();staBar->setParent(this);setStatusBar(staBar);//创建标签QLabel *label = new QLabel("UTF-8",this);staBar->addWidget(label);//文本this->edit = new QTextEdit(this);setCentralWidget(edit);//设置默认字体QFont font;font.setFamily("楷体");font.setPixelSize(20);font.setBold(true);this->edit->setFont(font);//设置默认颜色QColor color;color.setRed(100);this->edit->setTextColor(color);}JSB::~JSB()
{
}void JSB::closeEvent(QCloseEvent *event){if(this->edit->document()->isModified()){QMessageBox msgBox;msgBox.setText("内容以改变.");msgBox.setInformativeText("是否保存新内容?");msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);msgBox.setButtonText(QMessageBox::Save,"保存");msgBox.setButtonText(QMessageBox::Discard,"取消");msgBox.setButtonText(QMessageBox::Cancel,"不保存");msgBox.setDefaultButton(QMessageBox::Save);int ret = msgBox.exec();switch (ret) {case QMessageBox::Save:// Save was clickedthis->save_slot();break;case QMessageBox::Discard:// Don't Save was clickedevent->ignore();break;case QMessageBox::Cancel:// Cancel was clickedevent->accept();break;default:// should never be reachedbreak;}}else {event->accept();}}
void JSB::open_slot()
{QString filename = QFileDialog::getOpenFileName(this,"打开",".","*.*");QFile *file = new QFile;//设置打开的路径file->setFileName(filename);//只读bool ok = file->open(QIODevice::ReadOnly);if(ok){//问件指针关联文本流QTextStream stream(file);//UTF-8stream.setCodec("UTF-8");this->edit->setText(stream.readAll());//关闭文件file->close();delete file;//获取当前光标的位置QTextCursor cursor = this->edit->textCursor();//将光标移动到末尾cursor.movePosition(QTextCursor::End);//将设置好的光标放到edit中this->edit->setTextCursor(cursor);}}
void JSB::new_slot()
{JSB *w = new JSB;w->show();this->close();
}
void JSB::save_slot()
{QString filename = QFileDialog::getSaveFileName(this,"保存",".","*.*");QFile *file = new QFile;//设置打开的路径file->setFileName(filename);//只写bool ok = file->open(QIODevice::WriteOnly);if(ok){//文件指针关联文本流QTextStream stream(file);//UTF-8stream.setCodec("UTF-8");//QString str = this->edit->toPlainText();QString str = this->edit->toHtml();stream<<str;//关闭文件file->close();delete file;//清空editthis->edit->clear();}
}
void JSB::exit_slot()
{this->close();
}void JSB::copy_slot()
{this->edit->copy();
}
void JSB::patse_slot()
{this->edit->paste();
}
void JSB::cut_slot()
{this->edit->cut();
}
void JSB::redo_slot()
{this->edit->redo();
}
void JSB::undo_slot()
{this->edit->undo();
}void JSB::time_slot()
{QDateTime Time = QDateTime::currentDateTime();QString str = Time.toString("yyyy-MM-dd hh:mm:ss");this->edit->append(str);
}void JSB::color_slot()
{QColor color = QColorDialog::getColor(Qt::red,this,"颜色");if(color.isValid()){this->edit->setTextColor(color);}
}
void JSB::font_slot()
{bool ok;QFont font = QFontDialog::getFont(&ok,QFont("楷体",18,5,true),this,"字体");if(ok){this->edit->setFont(font);}
}void JSB::about_slot()
{}
void JSB::web_slot()
{QDesktopServices::openUrl(QUrl("https://blog.csdn.net/m0_72847002?spm=1010.2135.3001.5421"));
}
void JSB::ipv_slot()
{IPV * ipv = new IPV;ipv->show();}

登录功能的头文件

#ifndef LOGIN_H
#define LOGIN_H#include <QWidget>namespace Ui {
class Login;
}class Login : public QWidget
{Q_OBJECTpublic:explicit Login(QWidget *parent = nullptr);~Login();
public slots:void login();private:Ui::Login *ui;
};#endif // LOGIN_H

登录功能的函数实现

#include "login.h"
#include "ui_login.h"
#include "jsb.h"
Login::Login(QWidget *parent) :QWidget(parent),ui(new Ui::Login)
{ui->setupUi(this);this->setWindowTitle("登录");this->setWindowIcon(QIcon(":/image/Jsb3.png"));connect(ui->dl,&QPushButton::clicked,this,&Login::login);}Login::~Login()
{delete ui;
}void Login::login()
{if(ui->id->text() == "1" && ui->passwd->text()=="1"){JSB *jsb = new JSB;jsb->show();this->close();}
}

登录功能的UI绘制

在这里插入图片描述

版本展示头文件

#ifndef IPV_H
#define IPV_H#include <QWidget>
#include <QMovie>
namespace Ui {
class IPV;
}class IPV : public QWidget
{Q_OBJECTpublic:explicit IPV(QWidget *parent = nullptr);~IPV();private:Ui::IPV *ui;
};#endif // IPV_H

版本号功能实现

#include "ipv.h"
#include "ui_ipv.h"IPV::IPV(QWidget *parent) :QWidget(parent),ui(new Ui::IPV)
{ui->setupUi(this);QMovie *movie = new QMovie(":/image/q.gif");ui->label->setMovie(movie);movie->start();}IPV::~IPV()
{delete ui;
}

版本号界面UI绘制

在这里插入图片描述

效果图

在这里插入图片描述
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/82883.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

chatgpt 优秀项目

chagpt token 获取&#xff1a;点击即可 一、pandala 项目 仓库地址&#xff1a;pandora docker 部署方案 拉取镜像 docker pull pengzhile/pandora本地启动镜像 docker run -d --name chatgpt-e PANDORA_ACCESS_TOKEN<access_token> -e PANDORA_SERVER0.0.0.0:<p…

Golang gorm 一对一关系

一对一关系 一对一关系比较少&#xff0c;一般用于表的扩展例如一张用户表&#xff0c;有很多字段那么就可以把它拆分为两张表&#xff0c;常用的字段放主表&#xff0c;不常用的字段放详情表。 针对用户表来说可以通过user去点出userinfo。 创建表和插入数据 package mainimp…

MySQL 清空表 截断表

清空表&#xff1a;delete from users&#xff1b; 清空表只是清空表中的逻辑数据&#xff0c;但是物理数据不清除&#xff0c;如主键值、索引等不被清除&#xff0c;还是原来的值。 截断表&#xff1a;truncate table users&#xff1b; 截断表可以用于删除表中 的所有数据…

纯js实现html指定页面导出word

因为最近做了范文网站需要&#xff0c;所以要下载为word文档&#xff0c;如果php进行处理&#xff0c;很吃后台服务器&#xff0c;所以想用前端进行实现。查询github发现&#xff0c;确实有这方面的插件。 js导出word文档所需要的两个插件&#xff1a; FileSaver.js jquery.w…

【AI视野·今日NLP 自然语言处理论文速览 第三十六期】Tue, 19 Sep 2023

AI视野今日CS.NLP 自然语言处理论文速览 Tue, 19 Sep 2023 (showing first 100 of 106 entries) Totally 106 papers &#x1f449;上期速览✈更多精彩请移步主页 Daily Computation and Language Papers Speaker attribution in German parliamentary debates with QLoRA-ada…

如何理解高效IO

目录 前言 1.如何理解高效的IO 2.五种IO模型 3.非阻塞IO 4.非阻塞代码编写 总结 前言 哈喽&#xff0c;很高兴和大家见面&#xff01;今天我们要介绍的关于IO的话题&#xff0c;在计算机中IO是非常常规的操作&#xff0c;例如将数据显示到外设&#xff0c;或者将数据从主…

微服务引擎

微服务引擎&#xff0c;MSE_微服务引擎 MSE-阿里云帮助中心 一、什么是微服务引擎MSE 微服务引擎MSE&#xff08;Microservices Engine&#xff09;是一个面向业界主流开源微服务生态的一站式微服务平台&#xff0c;提供注册配置中心&#xff08;原生支持Nacos/ZooKeeper/Eur…

【LeetCode75】第五十九题 第N个泰波那契数

目录 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 代码&#xff1a; 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 题目顾名思义&#xff0c;让我们求出第N个泰波那契数&#xff0c;也就是除了开头三个数之外&#xff0c;第四个数开始就是等于前三个数之…

基于 Alpine 环境构建 aspnetcore6-runtime 的 Docker 镜像

关于 Alpine Linux 此处就不再过多讲述&#xff0c;请自行查看相关文档。 .NET 支持的体系结构 下表列出了当前支持的 .NET 体系结构以及支持它们的 Alpine 版本。 这些版本在 .NET 到达支持终止日期或 Alpine 的体系结构受支持之前仍受支持。请注意&#xff0c;Microsoft 仅正…

Jenkins+Gitee+Docker+Ruoyi项目前后端分离部署

前言 描述&#xff1a;本文主要是用来记录 如何用标题上的技术&#xff0c;部署到云服务器上通过ip正常访问。 一、总览 1.1、Docker做的事 拉取 mysql 镜像拉取 redis 镜像拉取 jdk 镜像拉取 nginx 镜像 解释说明&#xff1a;前端项目的打包文件放在 nginx容器运行。后端…

PWMADC重要参数

频率的计算 1、 ARR&#xff08;TIM_Period&#xff09; 是计数值&#xff1b; 2、 PSC&#xff08;TIM_Prescaler&#xff09; 是预分频值。 频率计算公式&#xff1a;Fpwm 主频 / ((ARR1)*(PSC1))(单位&#xff1a;Hz) 占空比的计算 计算公式&#xff1a;duty circle TIM3…

部署大数据平台详细教程以及遇到的问题解答(ubuntu18.04下安装ambari2.7.3+HDP3.1.0)

节点准备: 我搭建的是3台,节点可以随意。建议最少是3台 hostname ip 角色 ubuntu-1804-1 172.21.73.53 从节点 ubuntu-1804-2 172.21.73.54 主节点 ubuntu-1804-3 172.21.73.55 从节点 一:关闭所有节点的防火墙 sudo ufw disable二:配置时钟同步NTP 所有节点安装ntp sud…

Lua学习笔记:探究package

前言 本篇在讲什么 理解Lua的package 本篇需要什么 对Lua语法有简单认知 对C语法有简单认知 依赖Visual Studio工具 本篇的特色 具有全流程的图文教学 重实践&#xff0c;轻理论&#xff0c;快速上手 提供全流程的源码内容 ★提高阅读体验★ &#x1f449; ♠ 一级…

腾讯云微服务平台 TSF 异地多活单元化能力重磅升级

导语 2023腾讯全球数字生态大会已于9月7-8日完美落幕&#xff0c;40专场活动展示了腾讯最新的前沿技术、核心产品、解决方案。 微服务与消息队列专场&#xff0c;腾讯云微服务平台 TSF 产品经理张桢带来了《腾讯云微服务平台 TSF 异地多活单元化能力重磅升级》的精彩演讲。本…

Linux入门教程||Linux磁盘管理

Linux 磁盘管理 Linux磁盘管理好坏管理直接关系到整个系统的性能问题。 Linux磁盘管理常用三个命令为df、du和fdisk。 df&#xff1a;列出文件系统的整体磁盘使用量du&#xff1a;检查磁盘空间使用量fdisk&#xff1a;用于磁盘分区 东风 df命令参数功能&#xff1a;检查文件…

Unity的配置文件在安卓路径下使用的方法

Unity的配置文件在安卓路径下使用的方法 前言 之前我做过的很多使用配置文件的Unity项目&#xff0c;后面的有些项目也有在安卓路径下读取json文件的需求。这几天有个需求是获取在安卓路径下配置文件里的数据&#xff0c;我在网上查了一些案例&#xff0c;简单实现了这个需求…

内网穿透的应用-Cloudreve搭建云盘系统,并实现随时访问

文章目录 1、前言2、本地网站搭建2.1 环境使用2.2 支持组件选择2.3 网页安装2.4 测试和使用2.5 问题解决 3、本地网页发布3.1 cpolar云端设置3.2 cpolar本地设置 4、公网访问测试5、结语 1、前言 自云存储概念兴起已经有段时间了&#xff0c;各互联网大厂也纷纷加入战局&#…

小样本目标检测:ECEA: Extensible Co-Existing Attention for Few-Shot Object Detection

论文作者&#xff1a;Zhimeng Xin,Tianxu Wu,Shiming Chen,Yixiong Zou,Ling Shao,Xinge You 作者单位&#xff1a;Huazhong University of Science and Technology; UCAS-Terminus AI Lab 论文链接&#xff1a;http://arxiv.org/abs/2309.08196v1 内容简介&#xff1a; 1&…

C++const关键字

本文旨在讲解C中相关const关键字的详解&#xff0c;希望读完本篇文章&#xff0c;可以让诸位对C中的const关键字有更深一步的认识&#xff01; 在C中&#xff0c;若想让类中某一个变量不再改变&#xff0c;可以使用const关键字进行修饰&#xff0c;让数据不被修改&#xff0c;使…

2023-09-19 LeetCode每日一题(打家劫舍 IV)

2023-09-19每日一题 一、题目编号 2560. 打家劫舍 IV二、题目链接 点击跳转到题目位置 三、题目描述 沿街有一排连续的房屋。每间房屋内都藏有一定的现金。现在有一位小偷计划从这些房屋中窃取现金。 由于相邻的房屋装有相互连通的防盗系统&#xff0c;所以小偷 不会窃取…