大佬教程收集整理的这篇文章主要介绍了c – 带有无符号Int的QSpinBox,用于十六进制输入,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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,用于十六进制输入所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。