QT的FindDialog
2013-08-09 09:43
671 查看
#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();
}
相关文章推荐
- 用python3+PyQt5改写Python Qt GUI快速编程的第七章实例Find Dialog
- QT4的FindDialog例子在VC6中编译时提示链接错误的一种直观的解决办法(包含过程思路)
- QT学习笔记之七 FindFileDialog
- Qt5程序发布QPrintDialog需要的插件
- Qt学习之路(18): Qt标准对话框之QInputDialog
- 基于Linux(中标麒麟)上QT的环境搭建——解决cannot find lGL的问题
- DialogFragment不能findViewById的解决方法
- make xconfig错误:Unable to find the QT3 installation
- QProgressDialog使用时不显示的可能问题 #Qt #C++
- Qt 编译demos\affine cannot find ldemo_shared
- Qt学习之路(18): Qt标准对话框之QInputDialog
- This application failed to start because it could not find or load the Qt platform plugin "xcb".
- linux下qt测试,提示cannot find IGL
- Qt5 中发布程序遇到could not find or load the Qt platform plugin "windows"
- 关于/usr/bin/ld: cannot find -lxxx (qt cannot find -lGL)
- Qt之findfiles
- Qt5 中发布程序遇到could not find or load the Qt platform plugin "windows"
- This application failed to start because it could not find or load the Qt platform plugin “... 分类: QT学习实践 2015-05-17 18:21 44人阅读 评论(0) 收藏
- This application failed to start because it could not find or load the Qt platform plugin “windows”错误解决方法
- Qt 中各种 Dialog