Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In need of a 64-bit unsigned QSpinBox (to fit large numbers like pointers, etc)
Forum Updated to NodeBB v4.3 + New Features

In need of a 64-bit unsigned QSpinBox (to fit large numbers like pointers, etc)

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boohbah
    wrote on last edited by
    #5

    The steps from the linked post do not seem to give a working spin box (as in, it doesn't even show a value). It seems I might have to reimplement a whole bunch of methods, like valueFromText, textFromValue, fixup, validate, the value/textChanged signals, and possibly even more.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      boohbah
      wrote on last edited by
      #6

      Hmm, a lot of QSpinBox's implementation also calls rather large private methods, so this goes beyond just a simple subclass to something quite a lot more arduous. Not sure what to do here. (Perhaps I could be mistaken, though.)

      JonBJ 1 Reply Last reply
      0
      • B boohbah

        Hmm, a lot of QSpinBox's implementation also calls rather large private methods, so this goes beyond just a simple subclass to something quite a lot more arduous. Not sure what to do here. (Perhaps I could be mistaken, though.)

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #7

        @boohbah
        That is true if you re-implement from QAbstractSpinBox. But to just make 64-bit if the outline solution at my referenced https://stackoverflow.com/a/15655190/489865 solution is sufficient (maybe with the addition for you of hex values) that does not involve private stuff.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          boohbah
          wrote on last edited by
          #8

          I don't understand. Doing what that post sent and the information it provides doesn't seem sufficient and I'm not sure how I'd approach the other two steps it mentioned.

          This is what I currently have, and it does practically nothing:

          class SpinBoxU64 : public QAbstractSpinBox {
          public:
          	explicit SpinBoxU64(QWidget* parent = nullptr);
          
          	uint64_t minimum() const;
          	void setMinimum(uint64_t min);
          
          	uint64_t maximum() const;
          	void setMaximum(uint64_t max);
          
          	void setRange(uint64_t min, uint64_t max);
          
          	uint64_t value() const;
          
          	void stepBy(int steps) override;
          
          public slots:
          	void setValue(uint64_t val);
          
          signals:
          	void valueChanged(uint64_t);
          
          private:
          	uint64_t m_minimum, m_maximum, m_value;
          };
          
          SpinBoxU64::SpinBoxU64(QWidget* parent) :
          	QAbstractSpinBox(parent),
          	m_minimum(0), m_maximum(100), m_value(0) {}
          
          uint64_t SpinBoxU64::minimum() const {
          	return m_minimum;
          }
          
          uint64_t SpinBoxU64::maximum() const {
          	return m_maximum;
          }
          
          uint64_t SpinBoxU64::value() const {
          	return m_value;
          }
          
          void SpinBoxU64::setMinimum(uint64_t min) {
          	m_minimum = min;
          }
          
          void SpinBoxU64::setMaximum(uint64_t max) {
          	m_maximum = max;
          }
          
          void SpinBoxU64::setValue(uint64_t value) {
          	m_value = value;
          }
          
          void SpinBoxU64::stepBy(int steps) {
          	m_value += steps;
          }
          

          I implemented some of the methods and properties that I need, such as minimum and maximum, I also implemented stepBy (which doesn't even seem to be called by anything at all when I put a qDebug call inside it), and derived from QAbstractSpinBox itself. Interacting with this spin box just does nothing.

          Where would I put the relevant lineEdit()->setText() call? Why a validator on the lineEdit itself when QAbstractSpinBox has its own virtual validate and fixup methods themselves, implying those should be reimplemented? What would be a good way to approach such a validator? Things are rather ambiguous and confusing at this point.

          JonBJ 1 Reply Last reply
          0
          • S Offline
            S Offline
            SamiV123
            wrote on last edited by
            #9

            I don't know what your use case is exactly but can't you use this as an offset relative to some known base value? Would that help?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              boohbah
              wrote on last edited by
              #10

              That could be one way of approaching it, but unfortunately less preferable than just a regular QLineEdit as now I would need a label next to the spin box to indicate what the address actually is.

              1 Reply Last reply
              0
              • B boohbah

                I don't understand. Doing what that post sent and the information it provides doesn't seem sufficient and I'm not sure how I'd approach the other two steps it mentioned.

                This is what I currently have, and it does practically nothing:

                class SpinBoxU64 : public QAbstractSpinBox {
                public:
                	explicit SpinBoxU64(QWidget* parent = nullptr);
                
                	uint64_t minimum() const;
                	void setMinimum(uint64_t min);
                
                	uint64_t maximum() const;
                	void setMaximum(uint64_t max);
                
                	void setRange(uint64_t min, uint64_t max);
                
                	uint64_t value() const;
                
                	void stepBy(int steps) override;
                
                public slots:
                	void setValue(uint64_t val);
                
                signals:
                	void valueChanged(uint64_t);
                
                private:
                	uint64_t m_minimum, m_maximum, m_value;
                };
                
                SpinBoxU64::SpinBoxU64(QWidget* parent) :
                	QAbstractSpinBox(parent),
                	m_minimum(0), m_maximum(100), m_value(0) {}
                
                uint64_t SpinBoxU64::minimum() const {
                	return m_minimum;
                }
                
                uint64_t SpinBoxU64::maximum() const {
                	return m_maximum;
                }
                
                uint64_t SpinBoxU64::value() const {
                	return m_value;
                }
                
                void SpinBoxU64::setMinimum(uint64_t min) {
                	m_minimum = min;
                }
                
                void SpinBoxU64::setMaximum(uint64_t max) {
                	m_maximum = max;
                }
                
                void SpinBoxU64::setValue(uint64_t value) {
                	m_value = value;
                }
                
                void SpinBoxU64::stepBy(int steps) {
                	m_value += steps;
                }
                

                I implemented some of the methods and properties that I need, such as minimum and maximum, I also implemented stepBy (which doesn't even seem to be called by anything at all when I put a qDebug call inside it), and derived from QAbstractSpinBox itself. Interacting with this spin box just does nothing.

                Where would I put the relevant lineEdit()->setText() call? Why a validator on the lineEdit itself when QAbstractSpinBox has its own virtual validate and fixup methods themselves, implying those should be reimplemented? What would be a good way to approach such a validator? Things are rather ambiguous and confusing at this point.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #11

                @boohbah
                A little extra Googling might have led you to 64bit int Spin Box in QT. The post there https://stackoverflow.com/a/32628421/489865, the See code of my Сustom QSpinBox. class QLongLongSpinBox derived from QAbstractSpinBox one, is 10 years old but looks like a complete implementation to me. Not that big. It's for a qlonglong/ qint64. You can change it to qulonglong/quint64/uint64_t. When you have it working add your hex/integer base code.

                Read through qspinbox64 in QT5.15.2 for updates to code/comments/other peoples' changes. The last post there may have an alternative implementation.

                1 Reply Last reply
                1
                • GaoboG Offline
                  GaoboG Offline
                  Gaobo
                  wrote on last edited by
                  #12

                  you may can refer to this code: https://github.com/AlekseyDurachenko/QtLongLongSpinBox,

                  JonBJ 1 Reply Last reply
                  0
                  • GaoboG Gaobo

                    you may can refer to this code: https://github.com/AlekseyDurachenko/QtLongLongSpinBox,

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #13

                    @Gaobo
                    Clicking on that link gives a "404 not found".
                    Correct link is: https://github.com/AlekseyDurachenko/QtLongLongSpinBox

                    GaoboG 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Gaobo
                      Clicking on that link gives a "404 not found".
                      Correct link is: https://github.com/AlekseyDurachenko/QtLongLongSpinBox

                      GaoboG Offline
                      GaoboG Offline
                      Gaobo
                      wrote on last edited by
                      #14

                      @JonB I'm getting some errors when editing the link🌚 Thanks for the correction.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved