Fixed Width Qt Font

I need to limit my own setFont() widget so that it only accepts fonts with a fixed width.

However, I cannot find how to programmatically determine if a particular QFont fixed width. Is there such an opportunity?

+3
source share
2 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.. } 
+3
source

Add YourWidget->setStylesheet("QWidget{font: 10pt "Ubuntu";}");

Thus, you can limit the size of your widget to 10pt and a font like Ubuntu, if you do not change it elsewhere programmatically.

0
source

All Articles