茶亭量子 |
2009-05-04 18:26 |
//ip.h #include <qwidget.h> #include <qstring.h> #include <qlineedit.h> #include <qvalidator.h>
#define IP_H
class IP : public QWidget { public: IP ( const QString & text, QWidget *parent, const char *name ); QString getValue(); private: QLineEdit * ip[4]; QIntValidator * ipv[4]; };
//ip.cpp #include <qwidget.h> #include <qlabel.h> #include <qfont.h> #include <qhbox.h> #include <qlineedit.h>
#include "ip.h"
IP::IP(const QString & text, QWidget *parent, const char *nombre) : QWidget(parent, nombre, 0) { QFont *fuente = new QFont("Arial", 14, QFont::Normal); fuente->setPixelSize(14); QLabel *label = new QLabel( this ); label->setFont(* fuente); label->setMinimumWidth(140); label->setMaximumWidth(140); QHBox * ipp = new QHBox((QWidget*) this); ipp->setMinimumWidth(140); ipp->setMaximumWidth(140); for (int i=0; i<4; i++) { ip = new QLineEdit((QWidget*) ipp, nombre); ip->setFont(* fuente); ip->setMinimumWidth(30); ip->setMaxLength(3); ipv = new QIntValidator(0, 255, (QObject*)ipp); ip->setValidator(ipv); }
label->move(0, 0); ipp->move(150, 0); label->setText(text); // ip->setInputMask("000.000.000.000; "); }
QString IP::getValue() { bool flag = false; for (int i=0; i<4; i++) if ( ip->text().isEmpty() ) flag = true; if (flag) return QString("0.0.0.0"); else return QString(ip[0]->text()+ "." + ip[1]->text() + "." + ip[2]->text() + "." + ip[3]->text()); }
代码来源:http://www.tuxum.org/browser/tuxum/tuxtalador/tuxtalador/ip.h?rev=218 这样的代码先在网上找吧,一般都是有解决方案的。 |
|