QT中,QFileDialog,QColorDialog,QFontDialog,QInputDialog对话框的简单使用

定义BuiltInDialog.h

#ifndef BUILTINDIALOG_H #define BUILTINDIALOG_H #include <QDialog> #include <QTextEdit> #include <QPushButton> #include <QFileDialog> class QTextEdit; class QPushButton; QT_BEGIN_NAMESPACE namespace Ui { class BuiltInDialog; } QT_END_NAMESPACE class BuiltInDialog : public QDialog { Q_OBJECT public: BuiltInDialog(QWidget *parent = nullptr); ~BuiltInDialog(); private: QTextEdit *textEditDisplay; QPushButton *filePushButton; QPushButton *colorPushButton; QPushButton *fontPushButton; QPushButton *inputPushButton; QPushButton *closePushButton; QPushButton *progressPushButton; int num; private slots: void slotFile(); void slotColor(); void slotFont(); void slotInput(); void slotProgress(); }; #endif // BUILTINDIALOG_H

实现BuiltInDialog.cpp

#include "builtindialog.h" #include "ui_builtindialog.h" #include <QTextStream> #include <QColorDialog> #include <QFontDialog> #include <QInputDialog> #include <QProcess> #include <QProgressDialog> #include <windows.h> #include <QVBoxLayout> BuiltInDialog::BuiltInDialog(QWidget *parent) : QDialog(parent) { num = 0; textEditDisplay = new QTextEdit(); filePushButton = new QPushButton("打开"); colorPushButton = new QPushButton("颜色"); fontPushButton = new QPushButton("字体"); inputPushButton = new QPushButton("保存"); closePushButton = new QPushButton("关闭"); progressPushButton = new QPushButton("进度"); QVBoxLayout *rightLayout = new QVBoxLayout(); rightLayout->addWidget(filePushButton); rightLayout->addWidget(colorPushButton); rightLayout->addWidget(fontPushButton); rightLayout->addWidget(inputPushButton); rightLayout->addWidget(progressPushButton); rightLayout->addWidget(closePushButton); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(textEditDisplay); mainLayout->addLayout(rightLayout); setLayout(mainLayout); connect(filePushButton,SIGNAL(clicked()),this,SLOT(slotFile())); connect(colorPushButton,SIGNAL(clicked()),this,SLOT(slotColor())); connect(fontPushButton,SIGNAL(clicked()),this,SLOT(slotFont())); connect(inputPushButton,SIGNAL(clicked()),this,SLOT(slotInput())); connect(progressPushButton,SIGNAL(clicked()),this,SLOT(slotProgress())); connect(closePushButton,SIGNAL(clicked()),this,SLOT(close())); } BuiltInDialog::~BuiltInDialog() { } void BuiltInDialog::slotFile() { QString str = QFileDialog::getOpenFileName(this, tr("open file dialog"), QDir::home().path(), "Text files(*.txt)"); QFile file(str); if(!file.open(QIODevice::ReadWrite)){ return ; } QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); num++; textEditDisplay->append(line); } } void BuiltInDialog::slotColor() { QPalette palette = textEditDisplay->palette(); QColor color = QColorDialog::getColor(palette.color(QPalette::Text),this); if(color.isValid()){ palette.setColor(QPalette::Text,color); textEditDisplay->setPalette(palette); } } void BuiltInDialog::slotFont() { bool ok; QFont font = QFontDialog::getFont(&ok); if(ok){ textEditDisplay->setFont(font); } } void BuiltInDialog::slotInput() { bool ok; QString filePath = QInputDialog::getText(this,tr("Input Dialog"),tr("InputSavePath:"),QLineEdit::Normal,QDir::home().dirName(),&ok); if(!ok) return; QFile file(filePath); if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){ return ; } QTextStream out(&file); QString a = textEditDisplay->toPlainText(); out << a << "\n"; } void BuiltInDialog::slotProgress() { QProgressDialog *progressDialog = new QProgressDialog(this); QFont font("ZYSong18030",12); progressDialog->setFont(font); progressDialog->setWindowModality(Qt::WindowModal); progressDialog->setMinimumDuration(10); progressDialog->setWindowTitle(tr("Copying.....")); progressDialog->setCancelButtonText(tr("Cancel")); progressDialog->setRange(0,num); for(int i = 1;i < num;i++){ progressDialog->setValue(i); qApp->processEvents(); Sleep(1); if(progressDialog->wasCanceled()) return ; } }

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

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

相关文章

终极指南:Textstat文本可读性分析工具深度解析

终极指南&#xff1a;Textstat文本可读性分析工具深度解析 【免费下载链接】textstat :memo: python package to calculate readability statistics of a text object - paragraphs, sentences, articles. 项目地址: https://gitcode.com/gh_mirrors/tex/textstat 在信息…

STM32CubeMX点亮LED灯实战案例:含引脚分配技巧

用STM32CubeMX点亮LED&#xff1a;从引脚分配到可靠控制的实战全解析你有没有过这样的经历&#xff1f;花了一整天时间写代码、查手册、连电路&#xff0c;结果按下下载按钮后——灯没亮。反复检查&#xff1a;电源正常、程序编译通过、烧录成功……可那颗小小的LED就是不工作。…

GitPoint移动端安全认证终极指南:OAuth保护与用户隐私完整方案

GitPoint移动端安全认证终极指南&#xff1a;OAuth保护与用户隐私完整方案 【免费下载链接】git-point GitHub in your pocket :iphone: 项目地址: https://gitcode.com/gh_mirrors/gi/git-point 在当今移动应用生态中&#xff0c;数据安全与用户隐私保护已成为开发者必…

缓存革命:Ristretto如何用智能门禁系统重塑内存管理

缓存革命&#xff1a;Ristretto如何用智能门禁系统重塑内存管理 【免费下载链接】ristretto A high performance memory-bound Go cache 项目地址: https://gitcode.com/gh_mirrors/ri/ristretto 在现代高并发系统中&#xff0c;内存缓存性能优化、缓存命中率提升、内存…

Ueli:终极跨平台快捷启动器,彻底改变你的工作方式

Ueli&#xff1a;终极跨平台快捷启动器&#xff0c;彻底改变你的工作方式 【免费下载链接】ueli Keystroke launcher for Windows and macOS 项目地址: https://gitcode.com/gh_mirrors/ue/ueli 还在为频繁寻找应用程序、文件和网页而烦恼吗&#xff1f;Ueli 作为一款革…

GameNative应用下载限制:从灰色按钮到流畅体验的完整指南

GameNative应用下载限制&#xff1a;从灰色按钮到流畅体验的完整指南 【免费下载链接】GameNative Lightweight unofficial Steam client for Android 项目地址: https://gitcode.com/gh_mirrors/ga/GameNative 当你满怀期待地打开GameNative&#xff0c;准备下载心仪的…

Redpill Recovery:群晖NAS系统崩溃的终极自救指南

Redpill Recovery&#xff1a;群晖NAS系统崩溃的终极自救指南 【免费下载链接】rr Redpill Recovery (arpl-i18n) 项目地址: https://gitcode.com/gh_mirrors/rr2/rr 还在为群晖NAS突然罢工而手足无措吗&#xff1f;系统崩溃、数据无法访问、重装又怕丢失重要文件——这…

OpenSCAD终极指南:从代码到3D模型的完全解析

OpenSCAD终极指南&#xff1a;从代码到3D模型的完全解析 【免费下载链接】openscad OpenSCAD - The Programmers Solid 3D CAD Modeller 项目地址: https://gitcode.com/gh_mirrors/op/openscad 在当今3D建模软件百花齐放的时代&#xff0c;有一款软件以其独特的设计哲…

React Stockcharts 数据适配器深度解析:高性能实时数据处理终极方案

React Stockcharts 数据适配器深度解析&#xff1a;高性能实时数据处理终极方案 【免费下载链接】react-stockcharts Highly customizable stock charts with ReactJS and d3 项目地址: https://gitcode.com/gh_mirrors/re/react-stockcharts React Stockcharts 数据适配…

终极指南:快速掌握PointMLP点云处理MLP框架

终极指南&#xff1a;快速掌握PointMLP点云处理MLP框架 【免费下载链接】pointMLP-pytorch [ICLR 2022 poster] Official PyTorch implementation of "Rethinking Network Design and Local Geometry in Point Cloud: A Simple Residual MLP Framework" 项目地址: …

Hunyuan3D-1终极指南:从零开始掌握AI 3D生成技术

Hunyuan3D-1终极指南&#xff1a;从零开始掌握AI 3D生成技术 【免费下载链接】Hunyuan3D-1 Tencent Hunyuan3D-1.0: A Unified Framework for Text-to-3D and Image-to-3D Generation 项目地址: https://gitcode.com/gh_mirrors/hu/Hunyuan3D-1 腾讯开源的Hunyuan3D-1是…

Keil5编译器5.06下载后的首次使用操作指南

从零开始搭建Keil5开发环境&#xff1a;编译器5.06的完整实战指南最近有几位刚接触嵌入式开发的朋友问我&#xff1a;“Keil5编译器5.06下载后&#xff0c;为什么新建工程总是报错&#xff1f;”、“头文件找不到怎么办&#xff1f;”、“明明代码写对了&#xff0c;怎么烧录进…

Paper服务器防作弊实战指南:从零构建安全游戏环境

Paper服务器防作弊实战指南&#xff1a;从零构建安全游戏环境 【免费下载链接】Paper 最广泛使用的高性能Minecraft服务器&#xff0c;旨在修复游戏性和机制中的不一致性问题 项目地址: https://gitcode.com/GitHub_Trending/pa/Paper 为什么你的Minecraft服务器需要防作…

实时数据架构压测方案:性能瓶颈分析+优化策略+实战经验

实时数据架构压测方案&#xff1a;性能瓶颈分析优化策略实战经验 一、引入与连接&#xff1a;为什么实时系统的压测容不得半点马虎&#xff1f; 1.1 一个让工程师失眠的大促夜 2023年618大促零点刚过&#xff0c;某头部电商平台的实时推荐系统突然“宕机”—— millions of 用户…

foobox-cn终极美化方案:从单调到惊艳的音乐播放体验革命

foobox-cn终极美化方案&#xff1a;从单调到惊艳的音乐播放体验革命 【免费下载链接】foobox-cn DUI 配置 for foobar2000 项目地址: https://gitcode.com/GitHub_Trending/fo/foobox-cn 还在忍受foobar2000默认界面的单调乏味吗&#xff1f;foobox-cn作为一款基于fooba…

GLM4.5-V视觉问答模型微调教程:ms-swift一站式解决方案

GLM4.5-V视觉问答模型微调实战&#xff1a;ms-swift全链路工程实践 在智能医疗、工业质检、教育辅助等场景中&#xff0c;如何让大模型“看懂”图像并准确回答复杂问题&#xff0c;正成为AI落地的关键挑战。一个放射科医生上传一张CT影像&#xff0c;希望模型能结合报告文本判断…

如何快速搭建高效的Nominatim开发环境?

如何快速搭建高效的Nominatim开发环境&#xff1f; 【免费下载链接】Nominatim 项目地址: https://gitcode.com/gh_mirrors/nom/Nominatim 作为一名地理编码系统的开发者&#xff0c;你是否曾经为搭建Nominatim开发环境而头疼&#xff1f;别担心&#xff0c;本文将带你…

算法能力速成秘籍:LeetCode-Solutions高效学习全攻略

算法能力速成秘籍&#xff1a;LeetCode-Solutions高效学习全攻略 【免费下载链接】LeetCode-Solutions &#x1f3cb;️ Python / Modern C Solutions of All 2963 LeetCode Problems (Weekly Update) 项目地址: https://gitcode.com/gh_mirrors/le/LeetCode-Solutions …

前端开发规范终极解决方案:彻底消除团队代码不一致性

前端开发规范终极解决方案&#xff1a;彻底消除团队代码不一致性 【免费下载链接】code-guide Standards for developing consistent, flexible, and sustainable HTML and CSS. 项目地址: https://gitcode.com/gh_mirrors/co/code-guide 还在为团队协作中的CSS命名冲突…

数据脱敏处理流程:保护用户隐私的合规性实践

数据脱敏处理流程&#xff1a;保护用户隐私的合规性实践 在大模型日益深入企业核心业务系统的今天&#xff0c;一个现实挑战摆在面前&#xff1a;如何让AI“聪明”起来的同时&#xff0c;又不让它“记太多”&#xff1f;尤其是在金融、医疗、政务等高度敏感领域&#xff0c;模型…