C++ GUI Qt4编程(04)-2.1findDialog
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的更多相关文章
- C++ GUI Qt4编程(10)-3.4spreadsheet
1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...
- C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar
1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...
- C++ GUI Qt4编程(08)-3.2spreadsheet-resource
1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...
- C++ GUI Qt4编程(07)-3.1menu
1. C++ GUI Qt4编程第三章,添加menu菜单. 2. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include < ...
- C++ GUI Qt4编程(03)-1.3layout
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...
- C++ GUI Qt4编程(02)-1.2quit
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...
- C++ GUI Qt4编程(01)-1.1Hello Qt
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...
- C++ GUI Qt4编程-创建自定义窗口部件
C++ GUI Qt4编程-创建自定义窗口部件 Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...
- C++ GUI Qt4 编程 (第二版)
[加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...
随机推荐
- 第一章Python简介
1.Python shell(Python命令解释器) 如下所示 2.Python的交互模式 如下 3.代码编辑器窗口 在上面的那些指令称为源代码. 4.在python中,缩进是有语法意义的. 在某行 ...
- sqlServer通过指定的起始时间,创建该时间段内以年、月、日为时间段的临时表
通过指定的起始时间,创建该时间段内以年.月.日为时间段的临时表 ALTER PROCEDURE [dbo].[YOUR_SP_Name] -- Add the parameters for t ...
- (转)正则表达式—RegEx(RegularExpressio)(三)
原文地址:http://www.cnblogs.com/feng-c-x/archive/2013/09/05/3302465.html 今日随笔,继续写一点关于正则表达式的 知识.前两天介绍了正则表 ...
- Word文件乱码XML
文章介绍 一个朋友写的文档因为异常关机,导致全部文件变成了xml的乱码,正好帮他解决了,感觉这些或许有些帮助,就先记录下来了. 破损文件介绍 文件破坏之后,打开全是xml格式的文档,结构如下. 恢复过 ...
- POJ - 3984 迷宫问题 BFS求具体路径坐标
迷宫问题 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...
- 解决"要执行请求的操作,WordPress需要访问您网页服务器的权限"
比如我们在VPS主机中创建WordPress站点的时候,会有需要在线安装主题.插件等,但是点击下载安装的时候会有"要执行请求的操作,WordPress需要访问您网页服务器的权限. 请输入您的 ...
- .net core in Docker 部署方案(随笔)
前一段时间由于项目需要 .net core 在docker下的部署,途中也遇到很多坑,看了各同行的博客觉得多多少少还是有些问题,原本不想写此篇文章,由于好友最近公司也需要部署,硬是要求,于是花了些时间 ...
- NSValue 值
前言 将任意数据类型包装成 OC 对象 1.比较两个 NSValue 类型数据的大小 NSValue *value1 = [NSValue valueWithPoint:NSMakePoint(10, ...
- 使用sshkey,禁用密码登陆,以及git仓库的搭建
使用sshkey,可以实现免密码登陆服务器,同时关闭ssh service的使用账号密码登陆功能即可 1.首先在客户机添加sshkey(如果是window系统的话需要安装shell终端工具,例如xsh ...
- Xamarin Forms:小马过河,王者归来
因为我媳妇的原因,去年下半年从零开始学习Android原生开发,做了一个答题库app.整体给我的感觉是入门难度不大,前期折腾一番,大部分时间都是花在开发上面,其实任何一门语言都是如此. 今年我又有另一 ...