pythonpython-3.xpyqtreadonlyqspinbox

disable editing in QSpinbox but enable arrows


I have a QSpinBox in which I want to enable the arrows (for up and down values) but disable inserting data by the user. I've tried using this:

QtGui.QSpinBox.setReadOnly(True)

But it doesn't work. All is disabled and the arrows are 'stuck'.


Solution

  • If you set the spin-box readonly, it will disable eveything. Instead, just set the line-edit readonly, and then buttons will still work:

    spinbox.lineEdit().setReadOnly(True)