1. Use the QT Designer to create the Gotocell dialog box.
2. Gotocelldialog.cpp
1#include <QRegExp>2 3#include"gotocelldialog.h"4 5Gotocelldialog::gotocelldialog (Qwidget *parent)6 : Qdialog (parent)7 {8SETUPUI ( This);/*Initialize the form*/9 /*the Setupui () function automatically converts any slot that conforms to the On_objectname_signalname () naming conventionTen connected to the Signalname () signal of the corresponding objectname. */ One A /*{0,2} in front of 2 can not have spaces, there are spaces, the Lineedit box cannot be entered*/ -Qregexp RegExp ("[a-za-z][1-9][0-9]{0,2}"); - /*Qregexpvalidator Inspector Class*/ the /*Pass this to the Qregexpvalidator constructor, making it a sub-object of the Gotocelldialog object*/ -Lineedit->setvalidator (NewQregexpvalidator (REGEXP, This)); - -Connect (OKButton, SIGNAL (clicked ()), This, SLOT (Accept ())); +Connect (CancelButton, SIGNAL (clicked ()), This, SLOT (Reject ())); - } + A /*enable or disable the OK button*/ at voidgotocelldialog::on_lineedit_textchanged () - { - /*Qlineedit::hasacceptableinput () uses the inspector set in the constructor to determine the validity of the content in the row editor*/ -Okbutton->setenabled (lineedit->hasacceptableinput ()); -}
3. Gotocelldialog.h
1 /**/2 #ifndef Gotocelldialog_h3 #defineGotocelldialog_h4 5#include <QDialog>6 7#include"ui_gotocelldialog.h"8 9 classGotocelldialog: PublicQdialog, PublicUi::gotocelldialogTen { One Q_object A - Public: -Gotocelldialog (Qwidget *parent =0); the - PrivateSlots: - voidon_lineedit_textchanged (); - }; + - #endif
4. main.cpp
1#include <QApplication>2 3#include"gotocelldialog.h"4 5 intMainintargcChar*argv[])6 {7 qapplication app (argc, argv);8 9Gotocelldialog *dialog =NewGotocelldialog;TenDialog->Show (); One A returnapp.exec (); - } - the #if0 - -#include <QApplication> -#include <QDialog> + -#include"ui_gotocelldialog.h" + A at intMainintargcChar*argv[]) - { - qapplication app (argc, argv); - - Ui::gotocelldialog Ui; -Qdialog *dialog =NewQdialog; in ui.setupui (dialog); -Dialog->Show (); to + returnapp.exec (); - } the * #endif
C + + GUI QT4 programming ( -2.2gotocell)