对话框
2011-11-24 20:36 Rollen Holt 阅读(765) 评论(0) 收藏 举报本例子涉及到了快捷键,信号,槽,读者自己看代码,我给出了框架。
find.h文件代码如下:
#ifndef FIND_H
#define FIND_H
#include <QtGui>
#include "ui_find.h"
class Find : public QDialog
{
Q_OBJECT
public:
Find(QWidget *parent = 0, Qt::WFlags flags = 0);
~Find();
signals:
void findNext1(const QString &str,Qt::CaseSensitivity cs);
void findPrevious1(const QString &str,Qt::CaseSensitivity cs);
private slots:
void findClicked();
void enableFindButton(const QString &str);
private:
Ui::FindClass ui;
QLabel *label;
QLineEdit *textLine;
QCheckBox *matchBox;
QCheckBox *searchBox;
QPushButton *findButton;
QPushButton *quitButton;
};
#endif // FIND_H
find.cpp代码如下:
#include "find.h"
Find::Find(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
label=new QLabel(tr("Find &What:"));
textLine=new QLineEdit();
label->setBuddy(textLine);
QHBoxLayout *hlayout=new QHBoxLayout();
hlayout->addWidget(label);
hlayout->addWidget(textLine);
findButton=new QPushButton(tr("&Find"));
findButton->setEnabled(false);
findButton->setDefault(true);
quitButton=new QPushButton(tr("&Quit"));
QVBoxLayout *vlayout=new QVBoxLayout();
vlayout->addWidget(findButton);
vlayout->addWidget(quitButton);
matchBox=new QCheckBox(tr("Match &Case"));
searchBox=new QCheckBox(tr("Search &Backword"));
QVBoxLayout *vlayout1=new QVBoxLayout();
vlayout1->addWidget(matchBox);
vlayout1->addWidget(searchBox);
QHBoxLayout *mainLayout=new QHBoxLayout();
mainLayout->addLayout(hlayout);
mainLayout->addLayout(vlayout);
mainLayout->addLayout(vlayout1);
setLayout(mainLayout);
setWindowTitle(tr("Find"));
setFixedHeight(sizeHint().height());
connect(textLine,SIGNAL(textChanged(const QString &)),this,SLOT(enableFindButton(const QString&)));
connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
connect(quitButton,SIGNAL(clicked()),this,SLOT(close()));
}
Find::~Find()
{
}
// void Find::findNext1(const QString &str,Qt::CaseSensitivity cs){
// //do something here
// }
//
// void Find::findPrevious1(const QString &str,Qt::CaseSensitivity){
// //do something here
// }
void Find::findClicked(){
QString text=textLine->text();
Qt::CaseSensitivity cs=matchBox->isChecked() ? Qt::CaseSensitive:Qt::CaseInsensitive;
if(searchBox->isChecked()){
emit findPrevious1(text,cs);
}else{
emit findNext1(text,cs);
}
}
void Find::enableFindButton(const QString &str){
findButton->setEnabled(!(str.isEmpty()));
}
main.cpp
#include "find.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Find w=new Find();
w.show();
return a.exec();
}
==============================================================================
本博客已经废弃,不在维护。新博客地址:http://wenchao.ren
我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员
==============================================================================
浙公网安备 33010602011771号