赞
踩
- #ifndef HEXSPINBOX_H
- #define HEXSPINBOX_H
- #include <QSpinBox>
- class QRegExpValidator;
- 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;
- };
-
- #endif
- #include <QtGui>
- #include "hexspinbox.h"
- HexSpinBox::HexSpinBox(QWidget *parent)
- : QSpinBox(parent)
- {
- setRange(0, 255);
- validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"), this);
- }
-
- QValidator::State HexSpinBox::validate(QString &text, int &pos) const
- {
- return validator->validate(text, pos);
- }
-
- int HexSpinBox::valueFromText(const QString &text) const
- {
- bool ok;
- return text.toInt(&ok, 16);
- }
-
- QString HexSpinBox::textFromValue(int value) const
- {
- return QString::number(value, 16).toUpper();
- }
- #include <QtGui/QTableWidget>
- #include <QtGui/QToolBar>
- #include <QtGui/QWidget>
- #include "hspinbox.h"
-
- QT_BEGIN_NAMESPACE
-
- class Ui_QMainClass
- {
- public:
- QWidget *centralWidget;
- QPushButton *pushButton;
- QTableWidget *tableWidget;
- QSpinBox *spinBox;
- HSpinBox *hspinBox;
custom.h
- #ifndef CUSTOM_H
- #define CUSTOM_H
- #include <QtGui/QWidget>
- #include "ui_test.h"
- class custom : public QWidget
- {
- Q_OBJECT
- public:
- custom(QWidget *parent = 0);
- ~custom();
- private:
- Ui::Form ui;
- };
-
- #endif // CUSTOM_H
custom.cpp
- #include "custom.h"
-
- custom::custom(QWidget *parent)
- : QWidget(parent)
- {
- ui.setupUi(this);
- }
-
- custom::~custom()
- {
-
- }
customplugin.h
- #ifndef CUSTOMPLUGIN_H
- #define CUSTOMPLUGIN_H
-
- #include <QDesignerCustomWidgetInterface>
-
- class customPlugin : public QObject, public QDesignerCustomWidgetInterface
- {
- Q_OBJECT
- Q_INTERFACES(QDesignerCustomWidgetInterface)
- public:
- customPlugin(QObject *parent = 0);
-
- bool isContainer() const;
- bool isInitialized() const;
- QIcon icon() const;
- QString domXml() const;
- QString group() const;
- QString includeFile() const;
- QString name() const;
- QString toolTip() const;
- QString whatsThis() const;
- QWidget *createWidget(QWidget *parent);
- void initialize(QDesignerFormEditorInterface *core);
-
- private:
- bool initialized;
- };
-
- #endif // CUSTOMPLUGIN_H
- #include "custom.h"
- #include <QtCore/QtPlugin>
- #include "customplugin.h"
- customPlugin::customPlugin(QObject *parent)
- : QObject(parent)
- {
- initialized = false;
- }
-
- void customPlugin::initialize(QDesignerFormEditorInterface */*core*/)
- {
- if (initialized)
- return;
- initialized = true;
- }
-
- bool customPlugin::isInitialized() const
- {
- return initialized;
- }
-
- QWidget *customPlugin::createWidget(QWidget *parent)
- {
- return new custom(parent);
- }
-
- QString customPlugin::name() const
- {
- return "custom";
- }
-
- QString customPlugin::group() const
- {
- return "My Plugins";
- }
-
- QIcon customPlugin::icon() const
- {
- return QIcon();
- }
-
- QString customPlugin::toolTip() const
- {
- return QString();
- }
-
- QString customPlugin::whatsThis() const
- {
- return QString();
- }
-
- bool customPlugin::isContainer() const
- {
- return false;
- }
-
- QString customPlugin::domXml() const
- {
- return "<widget class=\"custom\" name=\"custom\">\n"
- " <property name=\"geometry\">\n"
- " <rect>\n"
- " <x>0</x>\n"
- " <y>0</y>\n"
- " <width>100</width>\n"
- " <height>100</height>\n"
- " </rect>\n"
- " </property>\n"
- "</widget>\n";
- }
-
- QString customPlugin::includeFile() const
- {
- return "custom.h";
- }
-
- Q_EXPORT_PLUGIN2(custom, customPlugin)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。