首页 > 分享 > qt QFont参数问题

qt QFont参数问题

使用qDebug()打印出出来的参数:QFont( "微软雅黑,20,-1,5,50,0,0,0,0,0" )
第一个参数是字体,第二个参数是字体大小,其他参数都是什么能?看帮助文档参数最多的也只有这个
QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false)
没看到有这么多参数的,有谁知道每一个参数都是什么意思吗?

QFont的文档说明网址如下:

https://doc.qt.io/qt-5/qfont.html

------------------------分割线-------------------------

在网友的帮助下在qt源码中找到如下代码,猜测应该就是这些参数代表的意思了吧,

其中源码路径,C:QtQt5.9.05.9Srcqtbasesrcguitextqfont.cpp

源码如下:

QString QFont::toString() const
{
    const QChar comma(QLatin1Char(','));
    QString fontDescription = family() + comma +
        QString::number(     pointSizeF()) + comma +
        QString::number(      pixelSize()) + comma +
        QString::number((int) styleHint()) + comma +
        QString::number(         weight()) + comma +
        QString::number((int)     style()) + comma +
        QString::number((int) underline()) + comma +
        QString::number((int) strikeOut()) + comma +
        QString::number((int)fixedPitch()) + comma +
        QString::number((int)   false);

    QString fontStyle = styleName();
    if (!fontStyle.isEmpty())
        fontDescription += comma + fontStyle;

    return fontDescription;
}

------------------------分割线-------------------------

查看帮助文档

style和styleHint是枚举类型:

enum QFont::Style

This enum describes the different styles of glyphs that are used to display text.

Constant

Value

Description

QFont::StyleNormal

0

Normal glyphs used in unstyled text.

QFont::StyleItalic

1

Italic glyphs that are specifically designed for the purpose of representing italicized text.

QFont::StyleOblique

2

Glyphs with an italic appearance that are typically based on the unstyled glyphs, but are not fine-tuned for the purpose of representing italicized text.

enum QFont::StyleHint

Style hints are used by the font matching algorithm to find an appropriate default family if a selected font family is not available.

Constant

Value

Description

QFont::AnyStyle

?

leaves the font matching algorithm to choose the family. This is the default.

QFont::SansSerif

Helvetica

the font matcher prefer sans serif fonts.

QFont::Helvetica

0

is a synonym for SansSerif.

QFont::Serif

Times

the font matcher prefers serif fonts.

QFont::Times

?

is a synonym for Serif.

QFont::TypeWriter

Courier

the font matcher prefers fixed pitch fonts.

QFont::Courier

?

a synonym for TypeWriter.

QFont::OldEnglish

?

the font matcher prefers decorative fonts.

QFont::Decorative

OldEnglish

is a synonym for OldEnglish.

QFont::Monospace

?

the font matcher prefers fonts that map to the CSS generic font-family 'monospace'.

QFont::Fantasy

?

the font matcher prefers fonts that map to the CSS generic font-family 'fantasy'.

QFont::Cursive

?

the font matcher prefers fonts that map to the CSS generic font-family 'cursive'.

QFont::System

?

the font matcher prefers system fonts.

以下摘抄自:

https://blog.csdn.net/Carry_Qt/article/details/88866530?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.nonecase

QFontDialog 用来弹出对话框 来获得指定的字体

QFont常用属性

函数 描述

setFamily

设置字体

setPixelSize

设置字体像素大小

setBold

字体加粗

setItalic

斜体

setPointSize

设置字体大小

setOverline

上划线

setUnderline

下划线

setStrikeOut

删除线

setPixelSize()函数使用像素作为单位来设置字体大小

setPointSize()函数规定了实际中我们肉眼看到的字体的大小,与像素无关

使用setPixelSize函数设置大小,在像素大小不同的设备上显示的大小也不同

使用setPointSize函数设置大小,在不同设备上显示的大小是相同的

常用的字体

QFontDialog 用来弹出对话框 来获得指定的字体

(不知道样式的可以在ui的字体设置里面查看对应字体的样式)

宋体 SimSun

黑体 SimHei

微软雅黑 Microsoft YaHei

微软正黑体 Microsoft JhengHei

新宋体 NSimSun

新细明体 PMingLiU

细明体 MingLiU

标楷体 DFKai-SB

仿宋 FangSong

楷体 KaiTi

仿宋_GB2312 FangSong_GB2312

楷体_GB2312 KaiTi_GB2312

宋体:SimSuncss中中文字体(font-family)的英文名称

Mac OS的一些:

华文细黑:STHeiti Light [STXihei]

华文黑体:STHeiti

华文楷体:STKaiti

华文宋体:STSong

华文仿宋:STFangsong

儷黑 Pro:LiHei Pro Medium

儷宋 Pro:LiSong Pro Light

標楷體:BiauKai

蘋果儷中黑:Apple LiGothic Medium

蘋果儷細宋:Apple LiSung Light

Windows的一些:

新細明體:PMingLiU

細明體:MingLiU

標楷體:DFKai-SB

黑体:SimHei

新宋体:NSimSun

仿宋:FangSong

楷体:KaiTi

仿宋_GB2312:FangSong_GB2312

楷体_GB2312:KaiTi_GB2312

微軟正黑體:Microsoft JhengHei

微软雅黑体:Microsoft YaHei

装Office会生出来的一些:

隶书:LiSu

幼圆:YouYuan

华文细黑:STXihei

华文楷体:STKaiti

华文宋体:STSong

华文中宋:STZhongsong

华文仿宋:STFangsong

方正舒体:FZShuTi

方正姚体:FZYaoti

华文彩云:STCaiyun

华文琥珀:STHupo

华文隶书:STLiti

华文行楷:STXingkai

华文新魏:STXinwei

相关知识

请问大家QT如何显示思源黑体 !嵌入式QT
Qt 查询字符串数据
Qt
【QT教程】QT6 Web开发入门 QT Web
qt 中的打印程序编写流程
移植中文字库到tiny6410
qasmine:命令行运行Qt应用程序中的茉莉花规格测试
【Qt】QTest:编译Qt单元测试程序
Qt虚拟键盘更新,支持手写识别功能
毕设教程:基于嵌入式Linux和Qt实现的视频监控系统(Arm/树莓派/jetson)

网址: qt QFont参数问题 https://m.huajiangbk.com/newsview1074156.html

所属分类:花卉
上一篇: HDU1395 2^x mod
下一篇: 设A={a,b,c}B={0,1