字体对话框QFontDialog、消息对话框 QMessageBox和输入对话框 QInputDialog

本文主要是介绍字体对话框QFontDialog、消息对话框 QMessageBox和输入对话框 QInputDialog,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

界面如下

1. 字体对话框 QFontDialog

1.1 基本函数

 QFont getFont(bool *ok, const QFont &initial, QWidget *parent = nullptr, const QString &title = QString(), QFontDialog::FontDialogOptions options = FontDialogOptions())

返回值:QFont类型--字体

参数1:如果字体设置成功,ok返回true,否则返回false

参数2:设置初始字体

参数3:指定父对象

参数4:指定对话框标题

 QFont getFont(bool *ok, QWidget *parent = nullptr)

返回值:QFont类型--字体

参数1:如果字体设置成功,ok返回true,否则返回false

参数2:指定父对象

1.2 示例

QDialog

dialog.cpp

//字体对话框
void Dialog::on_pushButton_clicked()
{bool ok = false;//选择字体等信息,选择完后后保存在fontQFont font = QFontDialog::getFont(&ok,this);if(ok){qDebug()<<"字体设置成功"<<endl;}//这里可以将我们上次保存的font里的字体信息,作为再次设置字体的默认值
//    QFontDialog::getFont(&ok,font,this,"字体对话框");
}

点击

2. 消息对话框 QMessageBox

2.1 基本函数

关于类型

void about(QWidget *parent, const QString &title, const QString &text)  //about关于
void aboutQt(QWidget *parent, const QString &title = QString())

有争议类型

QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton) //critical有争议

信息提示类型

QMessageBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton) //信息提示

返回值:QMessageBox::StandardButton返回按钮

参数1:指定父对象

参数2:指定标题

参数3:指定提示的文本

参数4:指定对话框中的按钮

参数5:设置默认按钮

有疑问类型

QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = StandardButtons(Yes | No), QMessageBox::StandardButton defaultButton = NoButton)//有疑问

警告类型

 QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = Ok, QMessageBox::StandardButton defaultButton = NoButton)  //警告

2.2 示例

参数4  指定对话框中的按钮 的参数

QMessageBox::Ok           An"OK" button defined with the AcceptRole.
QMessageBox::Open        An "Open" button defined with the AcceptRole.
QMessageBox::Save        A "Save" button defined with the AcceptRole.
QMessageBox::Cancel        A "Cancel" button defined with the RejectRole.
QMessageBox::Close        A "Close" button defined with the RejectRole.
QMessageBox::Discard        A "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole.
QMessageBox::Apply        An "Apply" button defined with the ApplyRole.
QMessageBox::Reset        A "Reset" button defined with the ResetRole.
QMessageBox::RestoreDefaults        A "Restore Defaults" button defined with the ResetRole.
QMessageBox::Help            A "Help" button defined with the HelpRole.
QMessageBox::SaveAll        A "Save All" button defined with the AcceptRole.
QMessageBox::Yes            A "Yes" button defined with the YesRole.
QMessageBox::YesToAll        A "Yes to All" button defined with the YesRole.
QMessageBox::No            A "No" button defined with the NoRole.
QMessageBox::NoToAll        A "No to All" button defined with the NoRole.
QMessageBox::Abort        An "Abort" button defined with the RejectRole.
QMessageBox::Retry        A "Retry" button defined with the AcceptRole.
QMessageBox::Ignore        An "Ignore" button defined with the AcceptRole.
QMessageBox::NoButton        An invalid button.

QDialog

dialog.cpp

//消息对话框
void Dialog::on_pushButton_2_clicked()
{//弹出提示框,提示一些关于qt的东西
//    QMessageBox::aboutQt(this,"关于Qt的一些基本信息");//信息提示类型
//    QMessageBox::StandardButton btn=QMessageBox::information(this,"information","今天是星期五",QMessageBox::Ok|QMessageBox::Close);
//    if(btn==QMessageBox::Ok)
//    {
//        qDebug()<<"用户已经知晓"<<endl;//    }
//    else if(btn==QMessageBox::Close)
//    {
//        qDebug()<<"用户关闭"<<endl;
//    }//问题类型QMessageBox::StandardButton btn=QMessageBox::question(this,"question","你今天开心吗?",QMessageBox::Ok|QMessageBox::Close);if(btn==QMessageBox::Ok){qDebug()<<"我开心"<<endl;}else if(btn==QMessageBox::Close){qDebug()<<"不开心"<<endl;}}

3. 输入对话框 QInputDialog

3.1 基本函数

输入double类型

double getDouble(QWidget *parent, const QString &title, const QString &label, double value = 0, double min = -2147483647, double max = 2147483647, int decimals = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), double step = 1)

返回值:double,获取double类型的数据

参数1:指定父对象

参数2:指定标题

参数3:设置标签(提示的文本)

参数4:设置输入对话框显示的当前值

参数5:设置最小值

参数6:设置最大值

参数7:设置小数位数

参数8:设置输入是否成功的标志

参数9:设置window的标志

参数10:设置步进值

输入intleixing

int getInt(QWidget *parent, const QString &title, const QString &label, int value = 0, int min = -2147483647, int max = 2147483647, int step = 1, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

返回值:int 获取int 类型的数据

参数1:指定父对象

参数2:指定标题

参数3:设置标签(提示的文本)

参数4:设置输入对话框显示的当前值

参数5:设置最小值

参数6:设置最大值

参数7:设置步进值

参数8:设置输入是否成功的标志

参数9:设置window的标志

一些其他的类型的 函数原型

QString getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current = 0, bool editable = true, bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints = Qt::ImhNone)QString getMultiLineText(QWidget *parent, const QString &title, const QString &label, const QString &text = QString(), bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints = Qt::ImhNone)QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode = QLineEdit::Normal, const QString &text = QString(), bool *ok = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints = Qt::ImhNone)

3.2 示例

QDialog

dialog.cpp

//输入对话框
void Dialog::on_pushButton_3_clicked()
{bool ok=false;//输入double类型的数据double value=QInputDialog::getDouble(this,"输入对话框","请输入double类型的数据:",0.00,0.00,100.00,2,&ok,Qt::WindowFlags(),0.01);if(ok){qDebug()<<"value="<<value<<endl;}//上面的getDoble函数有的参数有默认参数,可以不写直接省略,如下
//    double value = QInputDialog::getDouble(this,"输入对话框","请输入double类型");//    qDebug()<<"value="<<value<<endl;}

这篇关于字体对话框QFontDialog、消息对话框 QMessageBox和输入对话框 QInputDialog的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/608956

相关文章

如何通过Python实现一个消息队列

《如何通过Python实现一个消息队列》这篇文章主要为大家详细介绍了如何通过Python实现一个简单的消息队列,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录如何通过 python 实现消息队列如何把 http 请求放在队列中执行1. 使用 queue.Queue 和 reque

解读Redis秒杀优化方案(阻塞队列+基于Stream流的消息队列)

《解读Redis秒杀优化方案(阻塞队列+基于Stream流的消息队列)》该文章介绍了使用Redis的阻塞队列和Stream流的消息队列来优化秒杀系统的方案,通过将秒杀流程拆分为两条流水线,使用Redi... 目录Redis秒杀优化方案(阻塞队列+Stream流的消息队列)什么是消息队列?消费者组的工作方式每

使用C/C++调用libcurl调试消息的方式

《使用C/C++调用libcurl调试消息的方式》在使用C/C++调用libcurl进行HTTP请求时,有时我们需要查看请求的/应答消息的内容(包括请求头和请求体)以方便调试,libcurl提供了多种... 目录1. libcurl 调试工具简介2. 输出请求消息使用 CURLOPT_VERBOSE使用 C

电脑没有仿宋GB2312字体怎么办? 仿宋GB2312字体下载安装及调出来的教程

《电脑没有仿宋GB2312字体怎么办?仿宋GB2312字体下载安装及调出来的教程》仿宋字体gb2312作为一种经典且常用的字体,广泛应用于各种场合,如何在计算机中调出仿宋字体gb2312?本文将为您... 仿宋_GB2312是公文标准字体之一,仿China编程宋是字体名称,GB2312是字php符编码标准名称(简

Java中Springboot集成Kafka实现消息发送和接收功能

《Java中Springboot集成Kafka实现消息发送和接收功能》Kafka是一个高吞吐量的分布式发布-订阅消息系统,主要用于处理大规模数据流,它由生产者、消费者、主题、分区和代理等组件构成,Ka... 目录一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者一、Kaf

通过C#获取PDF中指定文本或所有文本的字体信息

《通过C#获取PDF中指定文本或所有文本的字体信息》在设计和出版行业中,字体的选择和使用对最终作品的质量有着重要影响,然而,有时我们可能会遇到包含未知字体的PDF文件,这使得我们无法准确地复制或修改文... 目录引言C# 获取PDF中指定文本的字体信息C# 获取PDF文档中用到的所有字体信息引言在设计和出

SpringBoot 自定义消息转换器使用详解

《SpringBoot自定义消息转换器使用详解》本文详细介绍了SpringBoot消息转换器的知识,并通过案例操作演示了如何进行自定义消息转换器的定制开发和使用,感兴趣的朋友一起看看吧... 目录一、前言二、SpringBoot 内容协商介绍2.1 什么是内容协商2.2 内容协商机制深入理解2.2.1 内容

【测试】输入正确用户名和密码,点击登录没有响应的可能性原因

目录 一、前端问题 1. 界面交互问题 2. 输入数据校验问题 二、网络问题 1. 网络连接中断 2. 代理设置问题 三、后端问题 1. 服务器故障 2. 数据库问题 3. 权限问题: 四、其他问题 1. 缓存问题 2. 第三方服务问题 3. 配置问题 一、前端问题 1. 界面交互问题 登录按钮的点击事件未正确绑定,导致点击后无法触发登录操作。 页面可能存在

ActiveMQ—消息特性(延迟和定时消息投递)

ActiveMQ消息特性:延迟和定时消息投递(Delay and Schedule Message Delivery) 转自:http://blog.csdn.net/kimmking/article/details/8443872 有时候我们不希望消息马上被broker投递出去,而是想要消息60秒以后发给消费者,或者我们想让消息没隔一定时间投递一次,一共投递指定的次数。。。 类似

解决Office Word不能切换中文输入

我们在使用WORD的时可能会经常碰到WORD中无法输入中文的情况。因为,虽然我们安装了搜狗输入法,但是到我们在WORD中使用搜狗的输入法的切换中英文的按键的时候会发现根本没有效果,无法将输入法切换成中文的。下面我就介绍一下如何在WORD中把搜狗输入法切换到中文。