FACT++  1.0
SpinBoxHex.h
Go to the documentation of this file.
1 #ifndef FACT_SpinBoxHex
2 #define FACT_SpinBoxHex
3 
4 #include <QSpinBox>
5 
6 #include <iostream>
7 class QRegExpValidator;
8 
9 class SpinBoxHex : public QSpinBox
10 {
11 public:
12  SpinBoxHex(QWidget *p=0) : QSpinBox(p)
13  {
14  }
15 
16 protected:
17  QValidator::State validate(QString &txt, int &/*pos*/) const
18  {
19  bool ok;
20  txt.toInt(&ok, 16);
21 
22  return ok ? QValidator::Acceptable : QValidator::Invalid;
23  }
24 
25  QString textFromValue(int val) const
26  {
27  return QString::number(val, 16).right(8).rightJustified(8, '0').toLower().insert(4, ':');
28  }
29 
30  int valueFromText(const QString &txt) const
31  {
32  bool ok;
33  return txt.toInt(&ok, 16);
34  }
35 };
36 
37 #endif
38 
39 // **************************************************************************
45 // **************************************************************************
A QSpinBox which displays the value as hex-value.
Definition: SpinBoxHex.h:9
QValidator::State validate(QString &txt, int &) const
Definition: SpinBoxHex.h:17
SpinBoxHex(QWidget *p=0)
Definition: SpinBoxHex.h:12
int valueFromText(const QString &txt) const
Definition: SpinBoxHex.h:30
QString textFromValue(int val) const
Definition: SpinBoxHex.h:25