Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4: QSpinBox doesn't accept values higher than 100

Tags:

pyqt4

I am quite new to python and qt, i want to use a spinner that ranges from 0 - 1000000 but the QSpinBox wont go above 100 even when i set the max to be 1000000, i am sure it is really simple to do, bu i have been searching for ages and cannot find anything. here is the code i have used so far:

steps_spin = qt.QSpinBox()
steps_spin.setValue(10000)
steps_spin.setMinimum(100)
steps_spin.setSingleStep(100)

I hope you guys can help me!

like image 887
Ben Avatar asked Apr 22 '11 11:04

Ben


3 Answers

  • The default maximum for QSpinBox is 99, so setValue is limited to 99.
  • To setValue for something higher than 99 you must call setMaximum/setRange first:

    steps_spin = QtGui.QSpinBox()
    steps_spin.setMinimum(100)
    steps_spin.setMaximum(100000)
    # alternatively, you may call: steps_spin.setRange(100, 100000)
    steps_spin.setValue(10000)
    
like image 162
Yinon Ehrlich Avatar answered Nov 05 '22 17:11

Yinon Ehrlich


How about

steps_spin.setRange(0,1000000)
like image 32
Kien Truong Avatar answered Nov 05 '22 15:11

Kien Truong


From the PyQt4 documentation:

QSpinBox.__ init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a spin box with 0 as minimum value and 99 as maximum value, a step value of 1. The value is initially set to 0. It is parented to parent.

See also setMinimum(), setMaximum(), and setSingleStep().

You can find a similar text in the Qt documentation of Nokia.

Working code sample:

from PyQt4 import QtGui
app = QtGui.QApplication([])
steps_spin = QtGui.QSpinBox()
steps_spin.setMaximum(1000000)
steps_spin.setValue(10000)
steps_spin.setMinimum(100)
steps_spin.setSingleStep(100)
steps_spin.show()
like image 3
phobie Avatar answered Nov 05 '22 17:11

phobie