How to change the font size of a QInputDialog in PyQt?
<p><strong>The case of a simple message box</strong></p>

<p>I have figured out how to change the font size in simple PyQt dialog windows. Take this example:</p>

<pre><code>    # Create a custom font
    # ---------------------
    font = QFont()
    font.setFamily("Arial")
    font.setPointSize(10)

    # Show simple message box
    # ------------------------
    msg = QMessageBox()
    msg.setIcon(QMessageBox.Question)
    msg.setText("Are you sure you want to delete this file?")
    msg.setWindowTitle("Sure?")
    msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
    msg.setFont(font)
    retval = msg.exec_()
    if retval == QMessageBox.Ok:
        print('OK')
    elif retval == QMessageBox.Cancel:
        print('CANCEL')
</code></pre>

<p>The key to changing the font size is that you actually have a 'handle' to your message box. The variable <code>msg</code> is available to tweak the message box to your needs before showing it with <code>msg.exec_()</code>.</p>

<p><strong>The case of a simple input dialog</strong></p>

<p>The problem about the input dialog is that such handle is not present. Take this example:</p>

<pre><code>    # Show simple input dialog
    # -------------------------
    filename, ok = QInputDialog.getText(None, 'Input Dialog', 'Enter the file name:')
    if(ok):
        print('Name of file = ' + filename)
    else:
        print('Cancelled')
</code></pre>

<p>The input dialog object is created on-the-fly. I have no way to tweak it to my needs (eg. apply a different font).</p>

<p>Is there a way to get a handle to this <code>QInputDialog</code> object, before showing it?</p>

<p><strong>EDIT :</strong></p>

<p>I was adviced in the comments to try it with an HTML snippet:</p>

<pre><code>    filename, ok = QInputDialog.getText(None, 'Input Dialog', '&lt;html style="font-size:12pt;"&gt;Enter the file name:&lt;/html&gt;')
</code></pre>

<p>The result is as follows:</p>

<p><a href="http://i.stack.imgur.com/BtzNI.png" rel="nofollow"><img src="http://i.stack.imgur.com/BtzNI.png" alt="enter image description here"></a></p>

<p>As you can see, the text input field has still the small (unchanged) font size.</p>

<p>Thanks to the comments of @denvaar and @ekhumoro, I got the solution. Here it is:</p>

<pre><code>    # Create a custom font
    # ---------------------
    font = QFont()
    font.setFamily("Arial")
    font.setPointSize(10)

    # Create and show the input dialog
    # ---------------------------------
    inputDialog = QInputDialog(None)
    inputDialog.setInputMode(QInputDialog.TextInput)
    inputDialog.setWindowTitle('Input')
    inputDialog.setLabelText('Enter the name for this new file:')
    inputDialog.setFont(font)
    ok = inputDialog.exec_()
    filename = inputDialog.textValue()
    if(ok):
        print('Name of file = ' + filename)
    else:
        print('Cancelled')
</code></pre>

python python-3.x pyqt pyqt5