qdilog

 

Qt 学习中, Ha Ha - _ -................

 

#ifndef FINDDIALOG_H
#define FINDDIALOG_H

#include <QDialog>

class QLabel;
class QPushButton;
class QCheckBox;
class QLineEdit;

class FindDialog : public QDialog
{
    Q_OBJECT

public:
    FindDialog(QWidget * parent = 0);
private:
    void findNext(const QString &str, Qt::CaseSensitivity cs);
    void findPrevious(const QString &str, Qt::CaseSensitivity cs);
private slots:
    void findClicked();
    void enableFindButton(const QString &text);
private:
    QLabel *label;
    QLineEdit *lineEdit;
    QCheckBox *machCase;
    QCheckBox *searchBackward;
    QPushButton *okButton;
    QPushButton *cancelButton;
};

#endif // FINDDIALOG_H
 
#include <QtGui>
#include <finddialog.h>

FindDialog::FindDialog(QWidget *parent)
    :QDialog(parent)
{
    label = new QLabel(tr("&Find what"));
    lineEdit = new QLineEdit;
    label->setBuddy(lineEdit);

    machCase = new QCheckBox(tr("&Mach case"));
    searchBackward = new QCheckBox(tr("&Search Backward"));

    okButton = new QPushButton(tr("&Find"));
    okButton->setDefault(true);     // Enter key is
    okButton->setEnabled(false);
    cancelButton = new QPushButton(tr("Cancel"));
    QObject::connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableFindButton(QString))); //is not textEdited(QString)?
    QObject::connect(okButton, SIGNAL(clicked()), this, SLOT(findClicked()));
    QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));

    QHBoxLayout *topLeftLayout = new QHBoxLayout;
    topLeftLayout->addWidget(label);
    topLeftLayout->addWidget(lineEdit);

    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addLayout(topLeftLayout);   //addLayout相当于布局好了的容器,而addWidget相当于要加入这个容器中的东西
    leftLayout->addWidget(machCase);
    leftLayout->addWidget(searchBackward);

    QVBoxLayout *rightLayout = new QVBoxLayout;
    rightLayout->addWidget(okButton);
    rightLayout->addWidget(cancelButton);
    rightLayout->addStretch();

    QHBoxLayout *windowLayout = new QHBoxLayout;
    windowLayout->addLayout(leftLayout);
    windowLayout->addLayout(rightLayout);

    setLayout(windowLayout);
    setWindowTitle(tr("Find"));
    setFixedHeight(sizeHint().height());
}

void FindDialog::findNext(const QString &str, Qt::CaseSensitivity cs)
{
    QString tr1 = str;
    int cs1 = cs;
    cs1 += cs1
    //now none thing to do
    ;
}

void FindDialog::enableFindButton(const QString &text)
{
    okButton->setEnabled(!text.isEmpty());
}

void FindDialog::findPrevious(const QString &str, Qt::CaseSensitivity cs)
{
    QString str1 = str;
    int cs1 = cs;
    cs1 += cs1
    // NOW none thing to do
    ;
}
void FindDialog::findClicked()
{
    QString str = lineEdit->text();
    Qt::CaseSensitivity cs = machCase->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;

    if (searchBackward->isChecked())
    {
        emit this->findPrevious(str, cs);   //send signal
    }
    else
    {
        emit this->findNext(str, cs);
    }
}

 

#include <QApplication>
#include <finddialog.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    FindDialog *findDialog = new FindDialog;
    findDialog->show();

    return app.exec();
}


 


#include <QApplication>
#include <finddialog.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    FindDialog *findDialog = new FindDialog;
    findDialog->show();

    return app.exec();
}


 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值