<table><tr><td style="">ahmadsamir added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D28774">View Revision</a></tr></table><br /><div><div><blockquote style="border-left: 3px solid #8C98B8;
          color: #6B748C;
          font-style: italic;
          margin: 4px 0 12px 0;
          padding: 8px 12px;
          background-color: #F8F9FC;">
<div style="font-style: normal;
          padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D28774#647157" style="background-color: #e7e7e7;
          border-color: #e7e7e7;
          border-radius: 3px;
          padding: 0 4px;
          font-weight: bold;
          color: black;text-decoration: line-through;">D28774#647157</a>, <a href="https://phabricator.kde.org/p/dfaure/" style="
              border-color: #f1f7ff;
              color: #19558d;
              background-color: #f1f7ff;
                border: 1px solid transparent;
                border-radius: 3px;
                font-weight: bold;
                padding: 0 4px;">@dfaure</a> wrote:</div>
<div style="margin: 0;
          padding: 0;
          border: 0;
          color: rgb(107, 116, 140);"><p>I mean, the user can press cancel, that's when QColorDialog returns an invalid color.<br />
 If there was a concept like an invalid font we could do the same here, but there's no such concept in QFont.<br />
 So yep, no better way.</p></div>
</blockquote>

<p>Looking at the code, if the user presses cancel, "theFont" is returned unchanged; seems pretty good to me:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">int KFontChooserDialog::getFont(QFont &theFont, const KFontChooser::DisplayFlags &flags, QWidget *parent)
{
    KFontChooserDialog dlg(flags, parent);
    dlg.setObjectName(QStringLiteral("Font Selector"));
    dlg.setFont(theFont, flags & KFontChooser::FixedFontsOnly);

    const int result = dlg.exec();
    if (result == Accepted) {
        theFont = dlg.d->chooser->font();
        stripRegularStyleName(theFont);
    }
    return result;
}</pre></div>

<p>QFontDialog::getFont() returns a QFont, and one may pass a bool * to check the dialog result code:<br />
QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, FontDialogOptions options)</p>

<p>which is standard Qt behaviour from other dialogs/widgets that handle user yes/no use cases, IIRC.</p>

<p>The KFontChooer* approach is more "economical", the "initial" font and the font you get from the dialog if you press OK, are the same object, and the function returns the dialog result code. As some wise old builder once said "there's no right or wrong way to lay bricks, as long as it works".</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R236 KWidgetsAddons</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D28774">https://phabricator.kde.org/D28774</a></div></div><br /><div><strong>To: </strong>ahmadsamir, Frameworks, dfaure, cfeck<br /><strong>Cc: </strong>kde-frameworks-devel, LeGast00n, cblack, michaelh, ngraham, bruns<br /></div>