资源描述:
《qt窗口布局及自定义类.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、qt窗口布局及自定义类说明以下将通过一个例子讲解自定义类的qt程序设计的主要流程要设计的界面通过两个文件:finddialog.h和finddialog.cpp来实现,即定义一个类finddialog.h(1)#ifndefFINDDIALOG_H#defineFINDDIALOG_H#includeclassQCheckBox;classQLabel;classQLineEdit;classQPushButton;classFindDialog:publicQDialog{Q_OBJECTpublic:FindDia
2、log(QWidget*parent=0,constchar*name=0);signals:voidfindNext(constQString&str,boolcaseSensitive);voidfindPrev(constQString&str,boolcaseSensitive);privateslots:voidfindClicked();voidenableFindButton(constQString&text);private:QLabel*label;QLineEdit*lineEdit;QCheckBox*caseChe
3、ckBox;QCheckBox*backwardCheckBox;QPushButton*findButton;QPushButton*closeButton;};#endiffinddialog.h(2)#ifndefFINDDIALOG_H#defineFINDDIALOG_H#includeclassQCheckBox;classQLabel;classQLineEdit;classQPushButton;finddialog.h(3)classFindDialog:publicQDialog{Q_OBJECTp
4、ublic:FindDialog(QWidget*parent=0,constchar*name=0);signals:voidfindNext(constQString&str,boolcaseSensitive);voidfindPrev(constQString&str,boolcaseSensitive);privateslots:voidfindClicked();voidenableFindButton(constQString&text);finddialog.h(4)private:QLabel*label;QLineEdi
5、t*lineEdit;QCheckBox*caseCheckBox;QCheckBox*backwardCheckBox;QPushButton*findButton;QPushButton*closeButton;};#endiffinddialog.cpp(1)#include#include#include#include#include#include"finddialog.h"finddialog.cpp(2
6、)FindDialog::FindDialog(QWidget*parent,constchar*name):QDialog(parent,name){setCaption(tr("Find"));label=newQLabel(tr("Find&what:"),this);lineEdit=newQLineEdit(this);label->setBuddy(lineEdit);caseCheckBox=newQCheckBox(tr("Match&case"),this);backwardCheckBox=newQCheckBox(tr
7、("Search&backward"),this);findButton=newQPushButton(tr("&Find"),this);findButton->setDefault(true);findButton->setEnabled(false);closeButton=newQPushButton(tr("Close"),this);finddialog.cpp(3)connect(lineEdit,SIGNAL(textChanged(constQString&)),this,SLOT(enableFindButton(con
8、stQString&)));connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));connect(clos