界面如下
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:指定父对象
QDialog
dialog.cpp
//字体对话框
void Dialog::on_pushButton_clicked()
{
bool ok = false;
//选择字体等信息,选择完后后保存在font
QFont font = QFontDialog::getFont(&ok,this);
if(ok){
qDebug()<<"字体设置成功"<
点击
关于类型
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) //警告
参数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()<<"用户已经知晓"<
输入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)
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="<