Question

Is it possible to disable keyboard input for a QFontComboBox? The following code:

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class FontComboBox(QFontComboBox):

    def __init__(self, parent=None):
        super(FontComboBox, self).__init__(parent)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    fonts = FontComboBox()
    fonts.show()
    sys.exit(app.exec_())

gives me (Mac OS X 10.8, PyQt4.8) a combobox which is editable and lets the user input basically anything. QtCreator, on the other hand, has this nice solution:

qtcreator font-selector

which looks more like an ordinary QComboBox. I've searched far and wide but can't seem to find settings for disabling keyboard input/changing the look of QFontComboBox. Any ideas?

Was it helpful?

Solution

A QFontComboBox is a QComboBox (i.e. a subclass of it), so all you need to do is:

    fonts.setEditable(False)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top