finddialog.h

/*
* 未实现findNextSignal和findPreviousSignal
*/
#ifndef FINDDIALOG_H
#define FINDDIALOG_H #include <QDialog> class QLabel;
class QLineEdit;
class QCheckBox;
class QPushButton;
class QHBoxLayout;
class QVBoxLayout; class FindDialog : public QDialog
{
Q_OBJECT public:
/*构造函数*/
FindDialog(QWidget *parent = 0);
/*析构函数*/
~FindDialog(); signals:
void findNextSignal(const QString &str, Qt::CaseSensitivity cs);
void findPreviousSignal(const QString &str, Qt::CaseSensitivity cs); private slots:
void findClickedSlot();
void enableFindButtonSlot(const QString &text); private:
QLabel *label;
QLineEdit *lineEdit;
QPushButton *findButton;
QPushButton *closeButton;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QVBoxLayout *leftLayout;
QVBoxLayout *rightLayout;
QHBoxLayout *topLeftLayout;
QHBoxLayout *mainLayout;
}; #endif

finddialog.cpp

#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QVBoxLayout> #include "finddialog.h" /*构造函数*/
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent) /*基类*/
{
/*不设置伙伴关系的时候,运行时W下不显示一条横线,而是显示&What*/
label = new QLabel(tr("Find &What:"));
lineEdit = new QLineEdit;
label->setBuddy(lineEdit); caseCheckBox = new QCheckBox(tr("Match &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(enableFindButtonSlot(const QString &)));
connect(findButton, SIGNAL(clicked()), \
this, SLOT(findClickedSlot()));
connect(closeButton, SIGNAL(clicked()), \
this, SLOT(close())); topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit); leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox); rightLayout = new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch(); mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout); setLayout(mainLayout); setWindowTitle(tr("Find"));
} /*析构函数*/
FindDialog::~FindDialog()
{ } /**/
void FindDialog::findClickedSlot()
{
QString text = lineEdit->text(); /*判断大小写是否要匹配*/
Qt::CaseSensitivity cs = \
caseCheckBox->isChecked() ? Qt::CaseSensitive \
: Qt::CaseInsensitive; if (backwardCheckBox->isChecked())
{
emit findPreviousSignal(text, cs); /*发送信号*/
}
else
{
emit findNextSignal(text, cs);
}
} /*启用或禁用Find按钮*/
void FindDialog::enableFindButtonSlot(const QString &text)
{
findButton->setEnabled(!text.isEmpty());
}

main.cpp

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

C++ GUI Qt4编程(04)-2.1findDialog的更多相关文章

  1. C++ GUI Qt4编程(10)-3.4spreadsheet

    1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...

  2. C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar

    1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...

  3. C++ GUI Qt4编程(08)-3.2spreadsheet-resource

    1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...

  4. C++ GUI Qt4编程(07)-3.1menu

    1. C++ GUI Qt4编程第三章,添加menu菜单. 2. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include < ...

  5. C++ GUI Qt4编程(03)-1.3layout

    1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7:  Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...

  6. C++ GUI Qt4编程(02)-1.2quit

    1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7:  Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...

  7. C++ GUI Qt4编程(01)-1.1Hello Qt

    1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7:  Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...

  8. C++ GUI Qt4编程-创建自定义窗口部件

    C++ GUI Qt4编程-创建自定义窗口部件   Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...

  9. C++ GUI Qt4 编程 (第二版)

    [加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...

随机推荐

  1. Part4_lesson3---U-Boot工作流程分析

    1.程序入口 我们从什么地方去找入口呢,首先是打开顶层目录的makefile文件,在这个文件里面,每一个uboot支持的开发板都有一个配置选项,比如说,搜索smdk2440,结果如下 我们主要关注上图 ...

  2. javascript总结5:js常见的数据类型

    1 Number 数字类型 :包含正数,负数,小数 十进制表示: var n1 =23; 十六进制表示法:从0-9,a(A)-f(F)表示数字.以0x开头. var n2 = 0x42 2 字符串数据 ...

  3. 在IE11(Win10)中检查up6.2配置

      1.按F12,打开调试模式    2.打开调试程序选项卡 说明:在调试程序选项卡中可看到IE加载的脚本信息是否正确.因为IE有缓存,导致脚本有时不是最新的.    3.打开脚本,up6.js   ...

  4. Java 扫描器类 Scanner类

    1.Scanner是SDK1.5新增的一个类,可是使用该类创建一个对象.Scanner reader=new Scanner(System.in); 2.reader对象调用下列方法(函数),读取用户 ...

  5. 日期多选插件Kalendae.js

    在项目中要实现日期多选的功能,于是在网上找到Kalendae.js,此文主要记录本人对于Kalendae.js的一些用法,以便以后查阅,希望对读者也有所帮助 主要内容如下: Kalendaejs一句话 ...

  6. React+gulp+browserify模块化开发

    阅读本文需要有React的基础知识,可以在React 入门实例教程和React中文官网进行基础学习. 没有React基础也可以学习本文,本文主要不是学习React,而是gulp+browserify进 ...

  7. windows下vscode 搭建python开发环境

    1.vscode https://code.visualstudio.com/ 下载 2.python下载 https://www.python.org/downloads/windows/  exe ...

  8. .Net Core 项目引用本地类库方式(二)

    上篇文章有详细的介绍.Net Core 项目中引用本地类库通过打包,然后Nugety引用方式,这里再介绍一种引用包的方式

  9. sed 增删改查详解以及 sed -i原理

    我为什么要详细记录sed命令:     sed 擅长取行.工作中三剑客使用频率最高,本篇文章将对sed命令常用的 增,删,改,查 进行详细讲解,以备以后工作中遗忘了查询,sed命令是作为运维人员来说, ...

  10. NSSet集合

    前言 NSSet:集合 NSSet 集合跟数组差不多,但 Set 集合不能存放相同的对象,它是一组单值对象的集合,被存放进集合中的数据是无序的,它可以是可变的,也可以是不变的. Xcode 7 对系统 ...