QT Learning Pathway (8): Create a dialog box (next)

Source: Internet
Author: User
Tags emit connect

Next, here is the source code section:

#include <QtGui>


#include "finddialog.h"





Finddialog::finddialog (qwidget *parent)


: Qdialog (parent)


{


label = new Qlabel (tr ("Find &what:");


lineedit = new Qlineedit;


Label->setbuddy (Lineedit);





Casecheckbox = new Qcheckbox (tr ("Match &case"));


Backwardcheckbox = new Qcheckbox (tr ("Search &backford"));





Findbutton = new Qpushbutton (tr ("&find"));


Findbutton->setdefault (TRUE);


findbutton->setenabled (FALSE);





CloseButton = new Qpushbutton (tr ("close"));





Connect (Lineedit, SIGNAL (textchanged (const qstring&)), this, SLOT (Enablefindbutton (const qstring&)));


Connect (Findbutton, SIGNAL (clicked ()), this, SLOT (findclicked ()));


Connect (CloseButton, SIGNAL (clicked ()), this, SLOT (Close ()));





qhboxlayout *topleftlayout = new Qhboxlayout;


topleftlayout->addwidget (label);


Topleftlayout->addwidget (Lineedit);





qvboxlayout *leftlayout = new Qvboxlayout;


leftlayout->addlayout (topleftlayout);


Leftlayout->addwidget (Casecheckbox);


Leftlayout->addwidget (Backwardcheckbox);





qvboxlayout *rightlayout = new Qvboxlayout;


Rightlayout->addwidget (Findbutton);


Rightlayout->addwidget (CloseButton);


Rightlayout->addstretch ();





qhboxlayout *mainlayout = new Qhboxlayout;


mainlayout->addlayout (leftlayout);


mainlayout->addlayout (rightlayout);


setlayout (mainlayout);





setwindowtitle (tr ("find"));


Setfixedheight (Sizehint (). height ());


}





Finddialog::~finddialog ()


{





}





void finddialog::findclicked ()


{


QString Text = Lineedit->text ();


qt::casesensitivity cs = casecheckbox->ischecked ()? qt::caseinsensitive:qt::casesensitive;


if (backwardcheckbox->ischecked ()) {


emit findprevious (text, CS);


} else {


emit FindNext (text, CS);


}


}





void Finddialog::enablefindbutton (const QString &text)


{


findbutton->setenabled (!text.isempty ());


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.