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

无人久伴 提交于 2019-12-03 11:48:11
  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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!