Search code examples
pythonpyqtqcombobox

Combobox does not resize properly to fit larger font size


When I create a combobox using PyQt5 on MacOS Big Sur, whether using the Designer or using code, the standard font size (13) allows for some padding around the text; this is what I want. A simple code would be:

from PyQt5 import QtWidgets as qtw

if __name__=='__main__':
    app = qtw.QApplication([])
    comboBox = qtw.QComboBox()
    comboBox.addItem('My first item')
    comboBox.addItem('My second item')
    comboBox.show()

enter image description here

However when I increase the font size to 25, for example by adding:

font = comboBox.font()
font.setPointSize(25)
comboBox.setFont(font)

I get the following:

enter image description here

which is clearly too cramped. Does anyone know how to change this? I get the same result setting the font size in Designer's property editor and setting it in a stylesheet.

Edit: Just tried on Ubuntu and here it works as expected...:

enter image description here


Solution

  • This issue has been accepted as a bug; see QTBUG-98042.