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:\Qt\Qt5.9.0\5.9\Src\qtbase\src\gui\text\qfont.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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值