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(); }