13

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!

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Ben
  • 131
  • 1
  • 1
  • 3

3 Answers3

17
  • 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)
    
Yinon Ehrlich
  • 586
  • 6
  • 14
4

How about

steps_spin.setRange(0,1000000)
Kien Truong
  • 11,179
  • 2
  • 30
  • 36
3

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()
phobie
  • 2,514
  • 1
  • 20
  • 21