I am quite new to python and qt, i want to use a spinne开发者_运维知识库r 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!
- 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)
How about
steps_spin.setRange(0,1000000)
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()
精彩评论