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 ...
随机推荐
- MySQL中having与where
having与where区别: where中不可以用聚合函数(条件字段是未分组中的字段),having中可以用聚合函(条件字段是分组后字段).不过这里也很好理解,SQL语句在执行是先执行select ...
- Celery笔记
异步任务神器 Celery 简明笔记 2016/12/19 · 工具与框架 · Celery, 异步 原文出处: FunHacks 在程序的运行过程中,我们经常会碰到一些耗时耗资源的操作,为了避 ...
- 复习action委托
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 使用dockerfile-maven-plugin发布docker到私有仓库
要想拥有私有docker仓库,需要安装registry镜像,最新版时2.0,具体可以看文档:https://docs.docker.com/registry/. 1. docker pull regi ...
- 编写高质量代码改善C#程序的157个建议——建议42:使用泛型参数兼容泛型接口的不可变性
建议42:使用泛型参数兼容泛型接口的不可变性 让返回值类型返回比声明的类型派生程度更大的类型,就是“协变”.如: public Employee GetAEmployee(string name) { ...
- 删除一个数的K位使原数变得最小
原创 给定一个n位正整数a, 去掉其中k个数字后按原左右次序将组成一个新的正整数.对给定的a, k寻找一种方案,使得剩下的数字组成的新数最小. 提示:应用贪心算法设计求解 操作对象为n位正整数,有可能 ...
- android获取USB设备的名称
1.注释内 .是三星设备可能不支持,需要更换的代码. 2.mUsbManager.是getSystemService(Context.USB_SERVICE)获的. 3. 从stackoverflow ...
- 快速获取.NET DLL文件编译时间
当用户现场汇报问题给我们, 我们比较关心的就有用户现场的DLL是什么版本号,是什么时候编译的. 有没有什么办法得到呢?办法是有的. 在网上找了很久终端找到这个软件非常地好用. 直接把文件拖到软件里就行 ...
- Linux 命令之chcon
chcon命令:修改对象(文件)的安全上下文.比如:用户:角色:类型:安全级别.主要用在selinux中用来更改安全上下文.命令格式: Chcon [OPTIONS…] CONTEXT FILES…. ...
- DataGridView自定义行样式和行标题
定义两个样式对象: //定义两种行样式 private DataGridViewCellStyle m_RowStyleNormal; private DataGridViewCellStyle m_ ...