I need to limit my own setFont() widget so that it only accepts fonts with a fixed width.
setFont()
However, I cannot find how to programmatically determine if a particular QFont fixed width. Is there such an opportunity?
QFont
Perhaps bool QFontInfo::fixedPitch() is the function you are looking for:
bool QFontInfo::fixedPitch()
void MyWidet::setFont ( const QFont& font ) { QFontInfo fontInfo(font); if(fontInfo.fixedPitch()) QWidget::setFont(font); // Otherwise ignore.. }
Add YourWidget->setStylesheet("QWidget{font: 10pt "Ubuntu";}");
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.