#include #include #include "formatterspinbox.h" FormatterSpinBox::FormatterSpinBox(QWidget *parent) : QSpinBox(parent) { m_nwidth = 2; } //! [1] int FormatterSpinBox::valueFromText(const QString &text) const { return text.toInt(); } //! [1] //! [2] QString FormatterSpinBox::textFromValue(int value) const { QString strTemp; return tr("%1").arg(value,m_nwidth,10,QLatin1Char('0')); } //! [2] void FormatterSpinBox::setFormatterWidth(int wid){ m_nwidth = wid; } void FormatterSpinBox::focusInEvent(QFocusEvent *event){ qDebug() << "focus in"; if(event->reason() == Qt::MouseFocusReason) QTimer::singleShot(200,this,SLOT(selectAll())); else selectAll(); emit focusInEdit(); } void FormatterSpinBox::focusOutEvent(QFocusEvent *event){ QSpinBox::focusOutEvent(event); emit focusOutEdit(); }