1 #ifndef QHEXSPINBOX_H
2 #define QHEXSPINBOX_H
3 #include <QtGui/QSpinBox>
4 
5 class QHexSpinBox : public QSpinBox
6 {
7 public:
8 	QHexSpinBox(QWidget *parent = 0):
QSpinBox(parent)9 			QSpinBox(parent)
10 	{
11 		setDisabled(true);
12 		setPrefix("0x");
13 	}
valueFromText(const QString & text)14 	int valueFromText(const QString &text) const
15 	{
16 		bool ok;
17 		int retVal = text.toInt(&ok, 16);
18 		if (ok)
19 			return retVal;
20 		return 0;
21 	}
22 
textFromValue(int value)23 	QString textFromValue(int value) const
24 	{
25 		return QString::number(value, 16).toUpper();
26 	}
validate(const QString & input,const int &)27 	QValidator::State validate(const QString &input, const int&)const
28 	{
29 		if (valueFromText(input))
30 			return QValidator::Acceptable;
31 		return QValidator::Invalid;
32 	}
33 };
34 #endif // QHEXSPINBOX_H
35