[Qt-interest] unsigned int QSpinBox
OJ
olejl77 at gmail.com
Fri Feb 13 08:01:26 CET 2009
I have successfully made a QSpinBox show hex numbers. The problem is
that I need it to support lager numbers than 'int' ('unsigned int'
would be sufficient). Does anyone have a tips on how I can do this
easily? This is my code:
hexspinbox.cpp:
#include <QtGui>
#include "hexspinbox.h"
HexSpinBox::HexSpinBox(QWidget *parent) : QSpinBox(parent) { }
int HexSpinBox::valueFromText(const QString &text) const
{
bool ok;
return text.toInt( &ok, 16 );
}
QString HexSpinBox::textFromValue(int value) const
{
return "0x" + QString::number(value,16).toUpper();
}
hexspinbox.h:
#ifndef __HEXSPINBOX_H__
#define __HEXSPINBOX_H__
#include <QSpinBox>
class HexSpinBox : public QSpinBox
{
Q_OBJECT
public:
HexSpinBox(QWidget *parent = 0);
//TODO: overload the default int to unsigned int
int valueFromText(const QString &text) const;
QString textFromValue(int value) const;
};
#endif // __HEXSPINBOX_H__
More information about the Qt-interest-old
mailing list