File: HexSpinBox.h

package info (click to toggle)
savvycan 220-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,456 kB
  • sloc: cpp: 61,803; sh: 293; javascript: 91; python: 44; makefile: 8
file content (24 lines) | stat: -rw-r--r-- 480 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once

#include <QSpinBox>


class HexSpinBox : public QSpinBox {

public:
    HexSpinBox(QWidget * parent = nullptr) :
        QSpinBox(parent)
    {
        setDisplayIntegerBase(16);
    }

protected:
    // this magic is needed to place minus sign BEFORE '0x' prefix
    QString textFromValue(int value) const override
    {
        QString text = QString::number(qAbs(value), 16);
        if (value < 0) return "-0x" + text;
        else return "0x" + text;
    }

};