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 ...
随机推荐
- Cookie存中文乱码的问题
有个奇怪的问题:登录页面中使用Cookie存值,Cookie中要存中文汉字.代码在本地调试,一切OK,汉字也能顺利存到Cookie和从Cookie中读出,但是放到服务器上不管用了,好好的汉字成了乱码, ...
- html页面源代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Python基础入门-While循环
讲完了for循环我们继续来看第二个循环,那就是while循环,while循环和for循环虽然都是循环,但是有着本质的不同.我们先来看下她们之间的区别和联系: While循环和for循环区别: 1.fo ...
- 编写高质量代码改善C#程序的157个建议——建议19:使用更有效的对象和集合初始化
建议19:使用更有效的对象和集合初始化 依赖于属性和FCL 3.5之后的语法规则,现在我们有了更加简洁有效的对象和集合初始化机制:对象和集合初始化设定项. 对象初始化: class Person { ...
- 简单接触oracle数据库nvl函数decode函数
SQL语句的DECODE()和NVL()函数用法 SELECT DECODE(choose_tool,0,'宝马',1,'电动车',2,'自行车','步行') AS my_tool FROM dat ...
- mac 地址查询
mac 地址由 6个字节(48bit)组成.前3个字节是厂商代码.输入厂商名称可查询相应的代码. http://standards.ieee.org/develop/regauth/oui/publi ...
- 【SQL】- 基础知识梳理(八) - 事务与锁
事务的概念 事务:若干条T-SQL指令组成的一个操作数据库的最小执行单元,这个整体要么全部成功,要么全部失败.(并发控制) 事务的四个属性:原子性.一致性.隔离性.持久性.称为事务的ACID特性. 原 ...
- 转载:ResultMap和ResultType在使用中的区别
在使用mybatis进行数据库连接操作时对于SQL语句返回结果的处理通常有两种方式,一种就是resultType另一种就是resultMap,下面说下我对这两者的认识和理解 resultType:当使 ...
- 趣图:后端工程师是怎样调试CSS的
一大波趣图:CSS的力量 趣图:前端 VS 后端
- 【ARC069F】Flags 2-sat+线段树优化建图+二分
Description 数轴上有 n 个旗子,第 ii 个可以插在坐标 xi或者 yi,最大化两两旗子之间的最小距离. Input 第一行一个整数 N. 接下来 N 行每行两个整数 xi, ...