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 ...
随机推荐
- 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别(转)
因CooCox用户数及影响力越来越大,CooCox团队也逐渐提高了对软件及代码协议的重视.在收集整理的过程中,一些归纳好的信息和大家分享一下.首先借用有心人士的一张相当直观清晰的图来划分各种协议:开源 ...
- 认识HttpContext.User
HttpContext.User,即IPrincipal .net源代码 namespace System.Security.Principal { /// <summary>Define ...
- VirtualBox安装增强功能(Linux)
我们在安装之前,必须得先安装好它所需要的依赖包,不然安装过程必定会出现错误! 一.安装依赖包 #yum install kernel-headers #yum install kernel-devel ...
- Displaying Speed and Direction Symbology from U and V vectors (转)
This blog shows you how to calculate and symbolize wind or current speed and direction when the unde ...
- 学习如何用VS2010创建ocx控件
1参考文章 (1)这一篇将使用vc创建ocx控件:http://blog.csdn.net/jiadelin/article/details/2917225 (2)这一篇文章有关vs2010创建act ...
- C# static 字段初始值设定项无法引用非静态字段、方法或属性
问题:字段或属性的问题字段初始值设定项无法引用非静态字段.方法 下面代码出错的原因,在类中定义的字段为什么不能用? public string text = test(); //提示 字段或属性的问题 ...
- javascript framework js常用框架
js常用框架 一.node.js 二.angularjs.js 三.react.js 四.webpack.js 五.flux.js 六.vue.js 七.bootstrap ...
- 基于CAS的单点登录实战(2)-- 搭建cas的php客户端
在这之前已经搭好了CAS服务端 基于CAS的单点登录实战(1)-- 搭建cas服务器 PHP-Client php-Client是官方支持的,去官网下个最新版就好了.phpCAS 接入很简单,解压放到 ...
- vim文本编辑
6.1 vi/vim 的使用 基本上 vi/vim 共分为三种模式,分别是命令模式(Command mode),插入模式(Insert mode)和底线命令模式(Last line mode). 6. ...
- 老男孩Day13作业:ORM学员管理系统
一.作业需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图: 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上 ...