Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt fixed-width font

Tags:

font-size

qt

I need to restrict a custom widget setFont() so that it only accepts fixed-width fonts.

However, I can’t find how to programmatically define whether a particular QFont is a fixed-width one. Is there such a possibility?

like image 731
Dmitry Savchenko Avatar asked Feb 04 '26 08:02

Dmitry Savchenko


1 Answers

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..
}
like image 156
Ammar Avatar answered Feb 05 '26 21:02

Ammar