Find对话框实现 平台 Qt5.3.2 MinGW4.8.2

注意创建时用QDialog

finddialog.h

#ifndef FINDDIALOG_H
#define FINDDIALOG_H #include <QDialog>
#include <QLabel>
#include <QCheckBox>
#include <QLineEdit>
#include <QPushButton>
#include <QLayout> class FindDialog : public QDialog
{
Q_OBJECT
public:
FindDialog(QWidget * parent = );
signals:
void findNext(const QString &str, Qt::CaseSensitivity cs);
void findPrevious(const QString &str, Qt::CaseSensitivity cs);
private slots:
void findClicked();
void enableFindButton(const QString &text);
private:
QLabel * label;
QLineEdit * lineEdit;
QCheckBox * caseCheckBox;
QCheckBox * backwardCheckBox;
QPushButton * findButton;
QPushButton * closeButton;
}; #endif // FINDDIALOG_H

finddialog.cpp

#include <QtGui>
#include "finddialog.h" FindDialog::FindDialog(QWidget *parent):QDialog(parent)
{
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(enableFindButton(const QString &)));
connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout * topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit); QVBoxLayout * leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox); QVBoxLayout * rightLayout = new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch(); QHBoxLayout * mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setWindowTitle(tr("Find"));
setFixedHeight(sizeHint().height());
} void FindDialog::findClicked()
{
QString text = lineEdit->text();
Qt::CaseSensitivity cs = caseCheckBox->isChecked()?Qt::CaseSensitive
:Qt::CaseInsensitive;
if(backwardCheckBox->isChecked())
{
emit findPrevious(text, cs);
}
else
{
emit findNext(text, cs);
}
} void FindDialog::enableFindButton(const QString &text)
{
findButton->setEnabled(!text.isEmpty());
}

mian.cpp

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

【QT】C++ GUI Qt4 学习笔记1的更多相关文章

  1. C++ GUI Qt4学习笔记01

    C++ GUI Qt4学习笔记01   qtc++signalmakefile文档平台 这一章介绍了如何把基本的C++只是与Qt所提供的功能组合起来创建一些简单的图形用户界面应用程序. 引入两个重要概 ...

  2. C++ GUI Qt4学习笔记03

    C++ GUI Qt4学习笔记03   qtc++spreadsheet文档工具resources 本章介绍创建Spreadsheet应用程序的主窗口 1.子类化QMainWindow 通过子类化QM ...

  3. C++ GUI Qt4学习笔记08

    C++ GUI Qt4学习笔记08   qtc++signal图形引擎文档 本章介绍Qt的二维图形引擎,Qt的二维图形引擎是基于QPainter类的.<span style="colo ...

  4. C++ GUI Qt4学习笔记09

    C++ GUI Qt4学习笔记09   qtc++ 本章介绍Qt中的拖放 拖放是一个应用程序内或者多个应用程序之间传递信息的一种直观的现代操作方式.除了剪贴板提供支持外,通常它还提供数据移动和复制的功 ...

  5. C++ GUI Qt4学习笔记05

    C++ GUI Qt4学习笔记05   qtc++正则表达式 QIntValidator           --  只让用户输入整数 QDoubleValidator     --  只让用户输入浮 ...

  6. C++ GUI Qt4学习笔记07

    C++ GUI Qt4   qtc++scrollobject编程 事件(event)是由串口系统或者Qt自身产生的,用以响应所发生的各类事情.当用户按下或者松开键盘或者鼠标上的按键时,就可以产生一个 ...

  7. 【QT】C++ GUI Qt4 学习笔记2

    Go To Cell 利用QT Desinger做好界面后加入的代码有 gotocelldialog.h #ifndef GOTOCELLDIALOG_H #define GOTOCELLDIALOG ...

  8. 【QT】C++ GUI Qt4 学习笔记3

    菜单界面的实现. 看书上第三章,好长,好多代码.我敲了半天,想看看效果,结果却显示不出来.仔细一看,发现spreadsheet的实现在第四章.郁闷.... 又到官网上下代码,结果居然不能运行.难道是因 ...

  9. 【QT】C++ GUI Qt4 学习笔记4

    感觉这本书的顺序设计的太不合理了,出现的最多的一句话就是后面会讲.按照使用的顺序讲不行吗?搞得代码都运行不了. 我决定先直接跳到73页,子类化QTableWidgetItem这一节.因为前面功能的实现 ...

随机推荐

  1. 使用LIBSVM工具实现样本分类预测——MatLab

    准备工作: https://www.csie.ntu.edu.tw/~cjlin/libsvm/,下载LIBSVM:(LIBSVM工具相较于MATLAB自带的工具:1).支持多分类及回归(‘-s 0’ ...

  2. PHP读取word文档

    在PHP中读取和写入WORD文档的代码 <? php // 建立一个指向新COM组件的索引 $word = new COM(”word.application”) or die(”Can't s ...

  3. 大数据之Ganglia安装1

    0.前期准备修改主机名.ip.iptables关闭:时间同步:ntpdate -s time.windows.com;软件准备ganglia-3.7.1.tar.gz.ganglia-web-3.7. ...

  4. Asp.Net网页头部动态加载标题、描述、关键字、css和js文件的方法

    首先head标签上添加runat="server". protected void Page_Load(object sender, EventArgs e) { Page.Tit ...

  5. hdu4747——Mex

    1.题目大意:对一个序列的每一个区间求Mex,最后所有的mex相加(mex就是SG的那个),力求nlogn... 2.分析:最近开始刷线段树了,还是有很多不会啊 首先把1-1 1-2 1-- 1-n这 ...

  6. BZOJ3052——糖果公园

    0.题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3052 1.题目大意:给定一颗n个点的无根树,每个点有一个颜色,要进行q次操作,有两种操 ...

  7. [Leetcode19] Remove Nth Node From End of List

    视频讲解  http://v.youku.com/v_show/id_XMTY1MTMzNjAyNA==.html (1)定义两个指针 ListNode fast = head; ListNode s ...

  8. js刷新页面的几种方法

    history.go(0) location.reload() location=location location.assign(location) document.execCommand('Re ...

  9. IE盒模型

    IE5.5及更早的版本使用的是IE盒模型,在在IE6及以上版本的浏览器中,浏览器支持一种解决了这种差异的可选的渲染模式,也开始遵循标准模式. IE盒模型和W3C盒模型的差异: IE盒模型,块元素的实际 ...

  10. Ubuntu固定ip和dns配置和查看

    1.查看dns: cat /etc/resolv.conf 2.Ubuntu固定ip sudo vim /etc/network/interfaces 修改如下部分: auto p3p1 iface ...