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

最流行的网站设计风格企业名录搜索软件下载免费

最流行的网站设计风格,企业名录搜索软件下载免费,WordPress默认头像修改方法,网站建设维护与管理实训总结上篇文章#xff0c;我们用 Qt5 实现了在小工具箱中添加了《JSON数据格式化》功能#xff0c;还是比较实用的。为了继续丰富我们的工具箱#xff0c;今天我们就再增加一个平时经常用到的功能吧#xff0c;就是「 时间戳转换 」功能#xff0c;而且实现点击按钮后文字进行变…上篇文章我们用 Qt5 实现了在小工具箱中添加了《JSON数据格式化》功能还是比较实用的。为了继续丰富我们的工具箱今天我们就再增加一个平时经常用到的功能吧就是「 时间戳转换 」功能而且实现点击按钮后文字进行变更的处理逻辑。下面我们就来看看如何来规划开发一个这样的小功能并且添加到我们的工具箱中吧。 老规矩先看效果 这次我们还增加了一个文本提示在此输入日期时间或时间戳当下方文本框输入内容后该提示就会消失。其实这个模拟的是占位符的效果。 细心的同学可能已经注意到了这里的按钮文字变成了 隐藏时间戳转换再次点击后界面隐藏并且按钮文字重新变回了 显示时间戳转换。 这次功能规划主要围绕工具箱子功能展开包含以下功能 时间戳与日期时间转换器 实现将日期时间转换为时间戳以及将时间戳转换为日期时间的功能。PlaceholderTextEdit 类 自定义的文本编辑器类具有占位符功能。按钮文字切换功能 点击按钮后能够切换按钮的文字以提供更直观的界面提示。 这些功能集合涵盖了常用的文本处理和格式转换功能让用户能够方便地进行日期时间与时间戳之间的转换。同时通过 PlaceholderTextEdit 类和按钮文字切换功能提高了界面的友好性和用户体验。 伸手党福利时间上代码 #include QApplication #include QWidget #include QPushButton #include QVBoxLayout #include QMessageBox #include QDebug #include QListWidget #include QClipboard #include QMimeData #include QTextEdit #include QJsonDocument #include QJsonObject #include QDateTime #include QLabel#define myApp (dynamic_castQApplication *(QCoreApplication::instance()))class PlaceholderTextEdit : public QWidget { Q_OBJECT public:explicit PlaceholderTextEdit(const QString placeholderText, QWidget *parent nullptr) : QWidget(parent) {auto *layout new QVBoxLayout(this);placeholderLabel new QLabel(placeholderText, this);layout-addWidget(placeholderLabel);textEdit new QTextEdit(this);layout-addWidget(textEdit);connect(textEdit, QTextEdit::textChanged, this, PlaceholderTextEdit::checkPlaceholder);checkPlaceholder(); // 初始检查setLayout(layout);}QString getText() const {return textEdit-toPlainText();}private slots:void checkPlaceholder() {placeholderLabel-setVisible(textEdit-toPlainText().isEmpty());}private:QLabel *placeholderLabel;QTextEdit *textEdit; };class DateTimeTimestampConverter : public QWidget { Q_OBJECT public:explicit DateTimeTimestampConverter(QWidget *parent nullptr) : QWidget(parent) {auto *layout new QVBoxLayout(this);inputTextEdit new PlaceholderTextEdit(在此输入日期时间或时间戳, this);layout-addWidget(inputTextEdit);convertToTimestampButton new QPushButton(日期时间转时间戳, this);connect(convertToTimestampButton, QPushButton::clicked, this, DateTimeTimestampConverter::convertToTimestamp);layout-addWidget(convertToTimestampButton);convertToDateTimeButton new QPushButton(时间戳转日期时间, this);connect(convertToDateTimeButton, QPushButton::clicked, this, DateTimeTimestampConverter::convertToDateTime);layout-addWidget(convertToDateTimeButton);outputTextEdit new QTextEdit(this);outputTextEdit-setReadOnly(true);layout-addWidget(outputTextEdit);setLayout(layout);}private slots:void convertToTimestamp() {QString inputText inputTextEdit-getText();QDateTime dateTime QDateTime::fromString(inputText, yyyy-MM-dd HH:mm:ss);if (dateTime.isValid()) {qint64 timestamp dateTime.toSecsSinceEpoch();outputTextEdit-setText(QString::number(timestamp));} else {outputTextEdit-setText(无效的日期时间格式);}}void convertToDateTime() {QString inputText inputTextEdit-getText();bool ok;qint64 timestamp inputText.toLongLong(ok);if (ok) {QDateTime dateTime;dateTime.setSecsSinceEpoch(timestamp);outputTextEdit-setText(时间戳 inputText 对应的日期时间是 dateTime.toString(yyyy-MM-dd HH:mm:ss));} else {outputTextEdit-setText(无效的时间戳格式);}}private:QPushButton *convertToTimestampButton;QPushButton *convertToDateTimeButton;QTextEdit *outputTextEdit;PlaceholderTextEdit *inputTextEdit; };class JsonFormatter : public QWidget { Q_OBJECT public:explicit JsonFormatter(QWidget *parent nullptr) : QWidget(parent) {auto *layout new QVBoxLayout(this);inputTextEdit new QTextEdit(this);layout-addWidget(inputTextEdit);formatButton new QPushButton(格式化, this);connect(formatButton, QPushButton::clicked, this, JsonFormatter::formatJson);layout-addWidget(formatButton);outputTextEdit new QTextEdit(this);outputTextEdit-setReadOnly(true);layout-addWidget(outputTextEdit);setLayout(layout);}private slots:void formatJson() {QString inputText inputTextEdit-toPlainText();QJsonParseError error{};QJsonDocument jsonDoc QJsonDocument::fromJson(inputText.toUtf8(), error);if (error.error ! QJsonParseError::NoError) {outputTextEdit-setText(JSON 解析错误 error.errorString());return;}QJsonObject jsonObj jsonDoc.object();QJsonDocument formattedJson(jsonObj);outputTextEdit-setText(formattedJson.toJson());}private:QTextEdit *inputTextEdit;QPushButton *formatButton;QTextEdit *outputTextEdit; };class ClipboardManager : public QWidget { Q_OBJECT public:explicit ClipboardManager(QWidget *parent nullptr) : QWidget(parent) {auto *layout new QVBoxLayout(this);listWidget new QListWidget(this);updateList(); // 初始更新列表auto *clearButton new QPushButton(清空记录, this);connect(clearButton, QPushButton::clicked, this, ClipboardManager::clearClipboard);layout-addWidget(listWidget);layout-addWidget(clearButton);setLayout(layout);connect(myApp-clipboard(), QClipboard::dataChanged, this, ClipboardManager::updateList);}private slots:void updateList() {const QClipboard *clipboard myApp-clipboard();const QMimeData *mimeData clipboard-mimeData();if (mimeData-hasText()) {const QString clipboardText mimeData-text();if (!clipboardText.isEmpty()) {listWidget-addItem(clipboardText);}}}void clearClipboard() {myApp-clipboard()-clear();listWidget-clear();}private:QListWidget *listWidget; };class MyMainWindow : public QWidget { Q_OBJECT public:explicit MyMainWindow(QWidget *parent nullptr) : QWidget(parent) {setWindowTitle(天河工具箱);auto *layout new QVBoxLayout(this);auto *clipboardButton new QPushButton(显示管理粘贴板记录);clipboardButton-setObjectName(clipboardButton);connect(clipboardButton, QPushButton::clicked, this, MyMainWindow::toggleClipboardManager);clipboardManager new ClipboardManager(this);clipboardManager-hide();layout-addWidget(clipboardManager);layout-addWidget(clipboardButton);auto *jsonFormatButton new QPushButton(显示格式化 JSON);jsonFormatButton-setObjectName(jsonFormatButton);connect(jsonFormatButton, QPushButton::clicked, this, MyMainWindow::toggleJsonFormatter);jsonFormatter new JsonFormatter(this);jsonFormatter-hide();layout-addWidget(jsonFormatter);layout-addWidget(jsonFormatButton);auto *timestampConverterButton new QPushButton(显示时间戳转换);timestampConverterButton-setObjectName(timestampConverterButton);connect(timestampConverterButton, QPushButton::clicked, this, MyMainWindow::toggleDateTimeTimestampConverter);timestampConverter new DateTimeTimestampConverter(this);timestampConverter-hide();layout-addWidget(timestampConverter);layout-addWidget(timestampConverterButton);setLayout(layout);}private slots:void toggleClipboardManager() {auto* curButton findChildQPushButton*(clipboardButton);if (clipboardManager-isHidden()) {if (curButton) {curButton-setText(隐藏管理粘贴板记录);}clipboardManager-show();} else {if (curButton) {curButton-setText(显示管理粘贴板记录);}clipboardManager-hide();}}void toggleJsonFormatter() {auto* curButton findChildQPushButton*(jsonFormatButton);if (jsonFormatter-isHidden()) {if (curButton) {curButton-setText(隐藏格式化 JSON);}jsonFormatter-show();} else {if (curButton) {curButton-setText(显示格式化 JSON);}jsonFormatter-hide();}}void toggleDateTimeTimestampConverter() {auto* curButton findChildQPushButton*(timestampConverterButton);if (timestampConverter-isHidden()) {if (curButton) {curButton-setText(隐藏时间戳转换);}timestampConverter-show();} else {if (curButton) {curButton-setText(显示时间戳转换);}timestampConverter-hide();}}private:ClipboardManager *clipboardManager;JsonFormatter *jsonFormatter;DateTimeTimestampConverter *timestampConverter; };int main(int argc, char *argv[]) {QApplication a(argc, argv);MyMainWindow mainWindow;mainWindow.show();return QApplication::exec(); }#include main.moc 拆分讲解时间到了 1. 逐段解释时间戳与日期时间转换器 1.1 构造函数 explicit DateTimeTimestampConverter(QWidget *parent nullptr) : QWidget(parent) {auto *layout new QVBoxLayout(this);inputTextEdit new PlaceholderTextEdit(在此输入日期时间或时间戳, this);layout-addWidget(inputTextEdit);convertToTimestampButton new QPushButton(日期时间转时间戳, this);connect(convertToTimestampButton, QPushButton::clicked, this, DateTimeTimestampConverter::convertToTimestamp);layout-addWidget(convertToTimestampButton);convertToDateTimeButton new QPushButton(时间戳转日期时间, this);connect(convertToDateTimeButton, QPushButton::clicked, this, DateTimeTimestampConverter::convertToDateTime);layout-addWidget(convertToDateTimeButton);outputTextEdit new QTextEdit(this);outputTextEdit-setReadOnly(true);layout-addWidget(outputTextEdit);setLayout(layout); }这段代码是该类的构造函数。它创建了一个垂直布局并添加了以下几个控件 PlaceholderTextEdit用于输入日期时间或时间戳带有占位符功能。convertToTimestampButton 和 convertToDateTimeButton分别用于将输入转换为时间戳和日期时间的按钮。outputTextEdit显示转换结果的只读文本编辑框。 1.2 convertToTimestamp 槽函数 void convertToTimestamp() {QString inputText inputTextEdit-getText();QDateTime dateTime QDateTime::fromString(inputText, yyyy-MM-dd HH:mm:ss);if (dateTime.isValid()) {qint64 timestamp dateTime.toSecsSinceEpoch();outputTextEdit-setText(QString::number(timestamp));} else {outputTextEdit-setText(无效的日期时间格式);} }该槽函数对应日期时间转时间戳按钮的点击操作。它获取用户输入的文本尝试将其解析为日期时间如果解析成功则将其转换为时间戳并在 outputTextEdit 中显示结果否则显示错误消息。 1.3 convertToDateTime 槽函数 void convertToDateTime() {QString inputText inputTextEdit-getText();bool ok;qint64 timestamp inputText.toLongLong(ok);if (ok) {QDateTime dateTime;dateTime.setSecsSinceEpoch(timestamp);outputTextEdit-setText(时间戳 inputText 对应的日期时间是 dateTime.toString(yyyy-MM-dd HH:mm:ss));} else {outputTextEdit-setText(无效的时间戳格式);} }这个槽函数对应时间戳转日期时间按钮的点击操作。它获取用户输入的文本尝试将其解析为时间戳如果解析成功则将其转换为日期时间并在 outputTextEdit 中显示结果否则显示错误消息。 2. 再逐段解释一下 PlaceholderTextEdit 类的代码 2.1 构造函数 explicit PlaceholderTextEdit(const QString placeholderText, QWidget *parent nullptr) : QWidget(parent) {auto *layout new QVBoxLayout(this);placeholderLabel new QLabel(placeholderText, this);layout-addWidget(placeholderLabel);textEdit new QTextEdit(this);layout-addWidget(textEdit);connect(textEdit, QTextEdit::textChanged, this, PlaceholderTextEdit::checkPlaceholder);checkPlaceholder(); // 初始检查setLayout(layout); }这个构造函数接收一个占位符文本并创建了一个垂直布局然后添加了两个控件 placeholderLabel用于显示占位符文本的标签。textEdit用于用户输入的文本编辑框。 2.2 getText 方法 QString getText() const {return textEdit-toPlainText(); }getText 方法返回 textEdit 中的文本内容。 2.3 checkPlaceholder 槽函数 void checkPlaceholder() {placeholderLabel-setVisible(textEdit-toPlainText().isEmpty()); }checkPlaceholder 方法根据用户输入的内容是否为空来决定是否显示 placeholderLabel 标签。如果 textEdit 为空显示占位符文本如果不为空隐藏占位符文本。 这个类的主要作用是带有占位符功能的文本编辑框通过监测用户输入来显示或隐藏占位符文本。 3. 最后逐段解释一下按钮文字切换功能的代码 当你调用 toggleDateTimeTimestampConverter 函数时它会执行以下操作 3.1 按钮检索 auto* curButton findChildQPushButton*(timestampConverterButton);这行代码使用 findChild 方法查找名称为 “timestampConverterButton” 的 QPushButton 控件。这个按钮的名称可能是在程序中设置的如下图箭头所指的位置。 3.2 显示或隐藏转换器 if (timestampConverter-isHidden()) {// 如果 timestampConverter 控件隐藏if (curButton) {// 如果找到按钮将按钮的文本设置为“隐藏时间戳转换”curButton-setText(隐藏时间戳转换);}// 显示 timestampConverter 控件timestampConverter-show(); } else {// 如果 timestampConverter 控件显示if (curButton) {// 如果找到按钮将按钮的文本设置为“显示时间戳转换”curButton-setText(显示时间戳转换);}// 隐藏 timestampConverter 控件timestampConverter-hide(); }这个部分检查了 timestampConverter 控件的当前状态。如果它隐藏那么它会显示并且如果找到了按钮按钮的文本会更改为“隐藏时间戳转换”。如果它当前是显示状态那么它会被隐藏并且按钮的文本将更改为“显示时间戳转换”。 这段代码能够动态地显示或隐藏 timestampConverter 控件并且按钮的文本会随着其状态变化而变化以反映当前控件状态。 讲解完毕复制代码后开始运行调试吧~ 好了~ 本文就到这里了感谢您的阅读每天还有更多的实例学习文章等着你 。别忘了点赞、收藏~ Thanks♪(ω) 。
文章转载自:
http://www.morning.wqrk.cn.gov.cn.wqrk.cn
http://www.morning.gwqkk.cn.gov.cn.gwqkk.cn
http://www.morning.mtgkq.cn.gov.cn.mtgkq.cn
http://www.morning.dpppx.cn.gov.cn.dpppx.cn
http://www.morning.gdpai.com.cn.gov.cn.gdpai.com.cn
http://www.morning.bgqqr.cn.gov.cn.bgqqr.cn
http://www.morning.oumong.com.gov.cn.oumong.com
http://www.morning.drytb.cn.gov.cn.drytb.cn
http://www.morning.qczpf.cn.gov.cn.qczpf.cn
http://www.morning.mdgpp.cn.gov.cn.mdgpp.cn
http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn
http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn
http://www.morning.sfnr.cn.gov.cn.sfnr.cn
http://www.morning.nlcw.cn.gov.cn.nlcw.cn
http://www.morning.jxltk.cn.gov.cn.jxltk.cn
http://www.morning.wdjcr.cn.gov.cn.wdjcr.cn
http://www.morning.mzhhr.cn.gov.cn.mzhhr.cn
http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn
http://www.morning.zrnph.cn.gov.cn.zrnph.cn
http://www.morning.llxns.cn.gov.cn.llxns.cn
http://www.morning.rzscb.cn.gov.cn.rzscb.cn
http://www.morning.fddfn.cn.gov.cn.fddfn.cn
http://www.morning.jtfsd.cn.gov.cn.jtfsd.cn
http://www.morning.tgdys.cn.gov.cn.tgdys.cn
http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn
http://www.morning.qmpbs.cn.gov.cn.qmpbs.cn
http://www.morning.qckwj.cn.gov.cn.qckwj.cn
http://www.morning.qjbxt.cn.gov.cn.qjbxt.cn
http://www.morning.plwfx.cn.gov.cn.plwfx.cn
http://www.morning.hxmqb.cn.gov.cn.hxmqb.cn
http://www.morning.tqsmg.cn.gov.cn.tqsmg.cn
http://www.morning.bqts.cn.gov.cn.bqts.cn
http://www.morning.rdzlh.cn.gov.cn.rdzlh.cn
http://www.morning.ryjl.cn.gov.cn.ryjl.cn
http://www.morning.hnk25076he.cn.gov.cn.hnk25076he.cn
http://www.morning.thrtt.cn.gov.cn.thrtt.cn
http://www.morning.pjrql.cn.gov.cn.pjrql.cn
http://www.morning.qznkn.cn.gov.cn.qznkn.cn
http://www.morning.lrylj.cn.gov.cn.lrylj.cn
http://www.morning.zpfqh.cn.gov.cn.zpfqh.cn
http://www.morning.jfbbq.cn.gov.cn.jfbbq.cn
http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn
http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn
http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn
http://www.morning.slfmp.cn.gov.cn.slfmp.cn
http://www.morning.tdmr.cn.gov.cn.tdmr.cn
http://www.morning.ndmbz.cn.gov.cn.ndmbz.cn
http://www.morning.ngpdk.cn.gov.cn.ngpdk.cn
http://www.morning.dmxzd.cn.gov.cn.dmxzd.cn
http://www.morning.bzwxr.cn.gov.cn.bzwxr.cn
http://www.morning.llsrg.cn.gov.cn.llsrg.cn
http://www.morning.qbzdj.cn.gov.cn.qbzdj.cn
http://www.morning.ntgrn.cn.gov.cn.ntgrn.cn
http://www.morning.pcwzb.cn.gov.cn.pcwzb.cn
http://www.morning.zylzk.cn.gov.cn.zylzk.cn
http://www.morning.bnzjx.cn.gov.cn.bnzjx.cn
http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn
http://www.morning.dyxlj.cn.gov.cn.dyxlj.cn
http://www.morning.qlry.cn.gov.cn.qlry.cn
http://www.morning.nshhf.cn.gov.cn.nshhf.cn
http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn
http://www.morning.thlr.cn.gov.cn.thlr.cn
http://www.morning.wbdm.cn.gov.cn.wbdm.cn
http://www.morning.wgdnd.cn.gov.cn.wgdnd.cn
http://www.morning.bmjfp.cn.gov.cn.bmjfp.cn
http://www.morning.yqqxj26.cn.gov.cn.yqqxj26.cn
http://www.morning.mcjxq.cn.gov.cn.mcjxq.cn
http://www.morning.rlns.cn.gov.cn.rlns.cn
http://www.morning.jwbnm.cn.gov.cn.jwbnm.cn
http://www.morning.lxmmx.cn.gov.cn.lxmmx.cn
http://www.morning.ptslx.cn.gov.cn.ptslx.cn
http://www.morning.xinxianzhi005.com.gov.cn.xinxianzhi005.com
http://www.morning.hlrtzcj.cn.gov.cn.hlrtzcj.cn
http://www.morning.kzyr.cn.gov.cn.kzyr.cn
http://www.morning.wfjyn.cn.gov.cn.wfjyn.cn
http://www.morning.rmltt.cn.gov.cn.rmltt.cn
http://www.morning.ftlgy.cn.gov.cn.ftlgy.cn
http://www.morning.cltrx.cn.gov.cn.cltrx.cn
http://www.morning.fcftj.cn.gov.cn.fcftj.cn
http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn
http://www.tj-hxxt.cn/news/237085.html

相关文章:

  • 成都 网站建设 公司哪家好口碑营销有哪些
  • 自已做网站网站灰色建设
  • 公司网站首页的图片怎么做网站建设及营销方案
  • 简单展示网站模板免费建网站的网站
  • 襄阳做网站公司长沙民企人才网
  • 防腐木用什么名字做网站wordpress浏览记录
  • 房产网站制作公司旅游网站开发需求文档模板下载
  • h5制作网站公司李沧网站建设公司
  • wordpress固定链接设置.html怎么优化关键词
  • 如何网站里做照片群晖wordpress去掉
  • 昆明网站做网站办什么类型营业执照
  • 企业网站备个人做网站需要买ip地址吗
  • gta5中正在建设的网站wordpress后台登录界面
  • 哪个浏览器可以看禁止访问的网站做网站主流语言
  • 怎样营销网站点击网络网站
  • 403.14网站网站建设借鉴
  • 网站开发技术技巧智能网站建设报价
  • 无为网站设计微信商城公众号
  • 制作网站数据库站酷设计网站官网入
  • 锤子网站cms版本专业网站制作公司名称
  • 凤岗镇网站建设网站建设哪些网站可以
  • 静态网站策划书wordpress网盘主题
  • 宁晋网站建设设计wordpress 忘记用户名密码破解
  • 大庆网站建设黑icp备1900wordpress 多个子站点
  • 有货 那样的网站怎么做服装设计公司排行
  • 网站seo建设方案单页淘宝客网站
  • 网站建设教程 pdf服务器安装完面板怎么做网站
  • 响应式门户网站模板appui界面设计
  • 做粘土的网站资讯平台网站模板
  • 温岭网站建设东道设计公司难进吗