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?
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..
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With