Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subclass QSpinBox so it could have int64 values as maxium and minimum

Tags:

qt

qspinbox

I need to implement a QSpinBox control which should be able to process int64 values as it's minimum & maximum values. Current implementation only supports int32 values.

End of the day my QSpinBox should accept any value between 9223372036854775807 and -9223372036854775808

What do I need to do, if I'm to achieve this by subclassing QAbstractSpinbox ?

like image 631
warunanc Avatar asked Mar 27 '13 08:03

warunanc


1 Answers

  1. Derive from QAbstractSpinBox.
  2. Add a QValidator to the QLineEdit to only allow valid int64 values.
  3. Add a property called value to provide access to the int64 member that actually holds the value.
  4. Reimplment stepBy(int steps) to modify the number.
  5. Implement the methods and properties specific to QSpinBox that you are interested in (minimum/maximum limits, prefix, suffix, etc).

Essentially you are maintaining two states: one is the actual int64 value, the other is the text held by the QLineEdit. Usually this is just updated by:

lineEdit()->setText(QString::number(myNumber));

But it will have to be tweaked slightly if the user wants a prefix or suffix.

like image 187
cmannett85 Avatar answered Nov 10 '22 01:11

cmannett85