formatterspinbox.cpp
888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <QtWidgets>
#include <QDebug>
#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();
}