tags:

views:

15

answers:

1

I'm trying to create a QSpinBox that accepts all numbers, but I'm having some trouble with hte maximums

 sbox = QSpinBox(self)
 sbox.setRange(-sys.maxint/88-1, sys.maxint/86)
 sbox.setValue(int(setting.value))

I wanted to just use sbox.setRange(-sys.maxint-1, sys.maxint) but then I couldn't enter anything, if I increase the range any more than above the whole spinner freaks out. Anybody knows why?

+1  A: 

that accepts all numbers

I assume you mean all integers rather than all numbers?

Remember that although PyQt is written in Python, the underlying Qt library is written in C++ so it most likely is limited to fixed-size integers of a certain width (for example 32-bit or 64-bit). If you try to use numbers close to the limits then some internal calculations in QSpinBox might overflow and wrap around which could explain the unusual behaviour you see.

To allow any integers at all use a QLineEdit and then parse the contents to a Python integer using the int function. This will allow all integers to be entered (you can even go above sys.maxint). You will lose the spin arrows though.

Mark Byers