Qt定宽字体 [英] Qt fixed-width font
本文介绍了Qt定宽字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要限制自定义小部件setFont()
,以便它仅接受固定宽度的字体.
I need to restrict a custom widget setFont()
so that it only accepts fixed-width fonts.
但是,我找不到如何以编程方式定义特定的QFont
是否为固定宽度的.有这种可能性吗?
However, I can’t find how to programmatically define whether a particular QFont
is a fixed-width one. Is there such a possibility?
推荐答案
也许 bool QFontInfo::fixedPitch()
是您要查找的功能:
Perhaps bool QFontInfo::fixedPitch()
is the function you are looking for:
void MyWidet::setFont ( const QFont& font )
{
QFontInfo fontInfo(font);
if(fontInfo.fixedPitch())
QWidget::setFont(font);
// Otherwise ignore..
}
这篇关于Qt定宽字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文