Find dialog implements platform Qt5.3.2 MinGW4.8.2
Note When creating a Qdialog
Finddialog.h
#ifndef Finddialog_h#defineFinddialog_h#include<QDialog>#include<QLabel>#include<QCheckBox>#include<QLineEdit>#include<QPushButton>#include<QLayout>classFinddialog: Publicqdialog{Q_object Public: Finddialog (Qwidget* Parent =0); Signals:voidFindNext (ConstQString &STR, qt::casesensitivity CS); voidFindPrevious (ConstQString &STR, qt::casesensitivity CS);PrivateSlots:voidfindclicked (); voidEnablefindbutton (ConstQString &text);Private: Qlabel*label; Qlineedit*LineEdit; Qcheckbox*Casecheckbox; Qcheckbox*Backwardcheckbox; Qpushbutton*Findbutton; Qpushbutton*CloseButton;};#endif //Finddialog_h
Finddialog.cpp
#include <QtGui>#include"finddialog.h"Finddialog::finddialog (Qwidget*parent): Qdialog (parent) {label=NewQlabel (TR ("Find &what:")); LineEdit=NewQlineedit; Label-SetBuddy (LineEdit); Casecheckbox=NewQcheckbox (TR ("Match &case")); Backwardcheckbox=NewQcheckbox (TR ("Search &backward")); Findbutton=NewQpushbutton (TR ("&find")); Findbutton->setdefault (true); Findbutton->setenabled (false); CloseButton=NewQpushbutton (TR ("Close")); Connect (LineEdit, SIGNAL (textChanged (ConstQString &)), This, SLOT (Enablefindbutton (ConstQString &))); Connect (Findbutton, SIGNAL (clicked ()), This, SLOT (findclicked ())); Connect (CloseButton, SIGNAL (clicked ()), This, SLOT (Close ())); Qhboxlayout* Topleftlayout =Newqhboxlayout; Topleftlayout-addwidget (label); Topleftlayout-AddWidget (LineEdit); Qvboxlayout* Leftlayout =Newqvboxlayout; Leftlayout-addlayout (topleftlayout); Leftlayout-AddWidget (Casecheckbox); Leftlayout-AddWidget (Backwardcheckbox); Qvboxlayout* Rightlayout =Newqvboxlayout; Rightlayout-AddWidget (Findbutton); Rightlayout-AddWidget (CloseButton); Rightlayout-Addstretch (); Qhboxlayout* Mainlayout =Newqhboxlayout; Mainlayout-addlayout (leftlayout); Mainlayout-addlayout (rightlayout); SetLayout (mainlayout); Setwindowtitle (TR ("Find")); Setfixedheight (Sizehint (). height ());voidfinddialog::findclicked () {QString text= lineedit->text (); Qt::casesensitivity CS= Casecheckbox->ischecked ()?qt::casesensitive:qt::caseinsensitive; if(backwardcheckbox->isChecked ()) {Emit findprevious (text, CS); } Else{emit findNext (text, CS); }}voidFinddialog::enablefindbutton (ConstQString &text) {Findbutton->setenabled (!text.isempty ());}
Mian.cpp
" finddialog.h " <QApplication>int main (intChar *argv[]) { qapplication a (argc, argv); New Finddialog; Dialog, Show (); return a.exec ();}
"QT" C + + GUI QT4 Learning Note 1