diff --git a/src/kfontchooser.cpp b/src/kfontchooser.cpp --- a/src/kfontchooser.cpp +++ b/src/kfontchooser.cpp @@ -129,6 +129,8 @@ QListWidget *sizeListBox = nullptr; QCheckBox *sizeIsRelativeCheckBox = nullptr; + QCheckBox *onlyFixedCheckbox = nullptr; + QFont selFont; QString selectedStyle; @@ -369,6 +371,21 @@ }); mainLayout->addWidget(sampleEdit); + + // Add a checkbox to toggle showing only monospace/fixed-width fonts + onlyFixedCheckbox = new QCheckBox(KFontChooser::tr("Show only monospaced fonts", "@option:check")); + onlyFixedCheckbox->setEnabled(flags ^ ShowDifferences); + onlyFixedCheckbox->setChecked(usingFixed); + + connect(onlyFixedCheckbox, &QAbstractButton::toggled, q, [this](const bool state) { + q->setFont(selFont, state); + }); + + if (flags & ShowDifferences) { // In this mode follow the state of the familyCheckbox + connect(familyCheckbox, &QAbstractButton::toggled, onlyFixedCheckbox, &QWidget::setEnabled); + } + mainLayout->addWidget(onlyFixedCheckbox); + // Finished setting up the chooser layout // lets initialize the display if possible diff --git a/tests/kfontchooserdialogtest.cpp b/tests/kfontchooserdialogtest.cpp --- a/tests/kfontchooserdialogtest.cpp +++ b/tests/kfontchooserdialogtest.cpp @@ -37,6 +37,9 @@ int nRet = KFontChooserDialog::getFont(font); qDebug() << font.toString(); + nRet = KFontChooserDialog::getFont(font, KFontChooser::FixedFontsOnly); + qDebug() << font.toString(); + KFontChooser::FontDiffFlags diffFlags; nRet = KFontChooserDialog::getFontDiff(font, diffFlags); qDebug() << font.toString();