QT的FindDialog

#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include<QDialog>
class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
 
class FindDialog:public QDialog
{
    Q_OBJECT
    //使用信号和槽时声明
public:
    FindDialog(QWidget* pParents = 0);
signals:
    void FindNext(const QString& str, Qt::CaseSensitivity cs);
    void FindPrevious(const QString& str, Qt::CaseSensitivity cs);
private slots:
    void findClicked();
    void enableFindButton(const QString& str);
private:
    QLabel* label;
    QLineEdit* lineEdit;
    QCheckBox* caseCheckBox;
    QCheckBox* backwardCheckBox;
    QPushButton* findButton;
    QPushButton* closeButton;
};
 
 
#endif // FINDDIALOG_H


#include<QtGui>
#include"FindDialog.h"
FindDialog::FindDialog(QWidget* pParent)
{
    label = new QLabel(tr("Find &what"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);
    caseCheckBox = new QCheckBox(tr("Math &case"));
    backwardCheckBox = new QCheckBox(tr("Search &backward"));
    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());
}
void FindDialog::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);
    }
}
void FindDialog::enableFindButton(const QString &str)
{
    findButton->setEnabled(!str.isEmpty());
}



#include<QtGui>
#include<QApplication>
#include<QHBoxLayout>
#include<QSlider>
#include<QSpinBox>
#include"FindDialog.h"
int main(int argc, char* argv[])
{
    QApplication app(argc, argv);
    FindDialog* pFind = new FindDialog;
    pFind->show();
    return app.exec();
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值