Created
January 21, 2015 13:24
-
-
Save hasherezade/a1fdf1f9d14f47020fa9 to your computer and use it in GitHub Desktop.
HexSpinBox (subclassed from QSpinBox)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "HexSpinBox.h" | |
| HexSpinBox::HexSpinBox(QWidget *parent) | |
| : QSpinBox(parent) | |
| { | |
| validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"), this); | |
| } | |
| QString HexSpinBox::textFromValue(int value) const | |
| { | |
| return QString::number(value, 16).toUpper(); | |
| } | |
| int HexSpinBox::valueFromText(const QString &text) const | |
| { | |
| bool ok; | |
| int val = text.toInt(&ok, 16); | |
| if (ok) return val; | |
| return 0; | |
| } | |
| QValidator::State HexSpinBox::validate(QString &text, int &pos) const | |
| { | |
| return validator->validate(text, pos); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <QtGui> | |
| class HexSpinBox : public QSpinBox | |
| { | |
| Q_OBJECT | |
| public: | |
| HexSpinBox(QWidget *parent = 0); | |
| protected: | |
| QValidator::State validate(QString &text, int &pos) const; | |
| int valueFromText(const QString &text) const; | |
| QString textFromValue(int value) const; | |
| private: | |
| QRegExpValidator *validator; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment