码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Qt5开发从入门到精通——第四篇(标准字体对话框类 getFont())


    欢迎小伙伴的点评✨✨,相互学习、互关必回、全天在线🍳🍳🍳
    博主🧑🧑 本着开源的精神交流Qt开发的经验、将持续更新续章,为社区贡献博主自身的开源精神👩‍🚀

    文章目录

    • 前言
    • 一、getFont()函数说明
    • 二、效果实例
    • 三、原码详解
      • dialog.h
      • dialog.cpp
      • main.cpp
    • 总结


    前言

    本章节将会给大家带来标准字体对话框QFontDialog 类的详细使用方法


    一、getFont()函数说明

    getFontO 函数是标准字体对话框 QFontDialog 类的 一个静态函数,该函数返回用户所选择的字体,下面是 getFontO函数形式:

    QFont getFont
    {
    	bool *ok,               //注
    	QWidget *parent = 0    //标准字体对话框的父窗口
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5

    注:若用户单击 “OK” 按钮,则该参数*ok 将设为 true, 函数返回用户所选择的字体;否则,将设为 false,此时函数返回默认字体。

    二、效果实例

    图一
    在这里插入图片描述

    三、原码详解

    dialog.h

    #ifndef DIALOG_H
    #define DIALOG_H
    
    #include 
    #include 
    #include 
    #include 
    #include 
    namespace Ui {
    class Dialog;
    }
    
    class Dialog : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit Dialog(QWidget *parent = nullptr);
        ~Dialog();
    
    private:
        Ui::Dialog *ui;
        QPushButton *fontBtn;
        QLineEdit *fontLineEdit;
        QGridLayout *mainLayout;
    private slots:
    void showFont();
    
    };
    
    #endif // DIALOG_H
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    dialog.cpp

    #include "dialog.h"
    #include "ui_dialog.h"
    
    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
        fontBtn = new QPushButton;
        fontBtn->setText(tr("字体标准对话框实例"));
        fontLineEdit = new QLineEdit;
        fontLineEdit->setText(tr("Welcome!"));   //显示更改的字符串
        mainLayout = new QGridLayout(this);
        mainLayout->addWidget(fontBtn,2,0);     //布局设计
        mainLayout->addWidget(fontLineEdit,2,1);
        connect(fontBtn,SIGNAL(clicked()),this ,SLOT(showFont()));  // 事件关联
    
    }
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    
    void Dialog::showFont()
    {
        bool ok;
        QFont f = QFontDialog::getFont(&ok);
        if (ok)
        {
            fontLineEdit->setFont(f);
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    main.cpp

    #include "dialog.h"
    #include 
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Dialog w;
        w.show();
    
        return a.exec();
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    总结

    标准字体对话框 getFont()函数也是在应用程序中经常用到的

  • 相关阅读:
    华为机试题:HJ6 质数因子
    摄像头识别安全帽
    RK3568驱动指南|第六篇-平台总线-第53章 probe函数编写实验
    Vue3 实现网页背景水印功能
    数据可视化在监控易中的艺术与实践
    通信原理 | 傅里叶变换(先立个贴在这,还没写好)
    11个常见的分类特征的编码技术
    Apache HTTPD 漏洞复现
    EI论文程序:Adaboost-BP神经网络的回归预测算法,可作为深度学习对比预测模型,丰富实验内容,自带数据集,直接运行!
    java Collections工具类
  • 原文地址:https://blog.csdn.net/weixin_44759598/article/details/126561442
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号