class HexSpinBox : public QSpinBox{public: HexSpinBox(bool only16Bits,QWidget *parent = 0) : QSpinBox(parent),m_only16Bits(only16Bits) { setPrefix("0x"); setdisplayIntegerBase(16); if (only16Bits) setRange(0,0xFFFF); else setRange(INT_MIN,INT_MAX); } unsigned int hexValue() const { return u(value()); } voID setHexValue(unsigned int value) { setValue(i(value)); }protected: QString textFromValue(int value) const { return QString::number(u(value),16).toupper(); } int valueFromText(const QString &text) const { return i(text.toUInt(0,16)); } qvalidator::State valIDate(QString &input,int &pos) const { QString copy(input); if (copy.startsWith("0x")) copy.remove(0,2); pos -= copy.size() - copy.trimmed().size(); copy = copy.trimmed(); if (copy.isEmpty()) return qvalidator::Intermediate; input = QString("0x") + copy.toupper(); bool okay; unsigned int val = copy.toUInt(&okay,16); if (!okay || (m_only16Bits && val > 0xFFFF)) return qvalidator::InvalID; return qvalidator::Acceptable; }private: bool m_only16Bits; inline unsigned int u(int i) const { return *reinterpret_cast<unsigned int *>(&i); } inline int i(unsigned int u) const { return *reinterpret_cast<int *>(&u); }};总结
以上是内存溢出为你收集整理的c – 带有无符号Int的QSpinBox,用于十六进制输入全部内容,希望文章能够帮你解决c – 带有无符号Int的QSpinBox,用于十六进制输入所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)