博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对话框
阅读量:6881 次
发布时间:2019-06-27

本文共 2875 字,大约阅读时间需要 9 分钟。

本例子涉及到了快捷键,信号,槽,读者自己看代码,我给出了框架。

find.h文件代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef FIND_H
#define FIND_H
 
#include <QtGui>
#include "ui_find.h"
 
class 
Find : 
public 
QDialog
{
    
Q_OBJECT
 
public
:
    
Find(QWidget *parent = 0, Qt::WFlags flags = 0);
    
~Find();
 
signals:
    
void 
findNext1(
const 
QString &str,Qt::CaseSensitivity cs);
    
void 
findPrevious1(
const 
QString &str,Qt::CaseSensitivity cs);
 
private 
slots:
    
void 
findClicked();
    
void 
enableFindButton(
const 
QString &str);
 
private
:
    
Ui::FindClass ui;
 
    
QLabel *label;
    
QLineEdit *textLine;
    
QCheckBox *matchBox;
    
QCheckBox *searchBox;
    
QPushButton *findButton;
    
QPushButton *quitButton;
};
 
#endif // FIND_H

 find.cpp代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "find.h"
 
Find::Find(QWidget *parent, Qt::WFlags flags)
    
: QDialog(parent, flags)
{
    
ui.setupUi(
this
);
 
    
label=
new 
QLabel(tr(
"Find &What:"
));
    
textLine=
new 
QLineEdit();
    
label->setBuddy(textLine);
    
QHBoxLayout *hlayout=
new 
QHBoxLayout();
    
hlayout->addWidget(label);
    
hlayout->addWidget(textLine);
 
    
findButton=
new 
QPushButton(tr(
"&Find"
));
    
findButton->setEnabled(
false
);
    
findButton->setDefault(
true
);
    
quitButton=
new 
QPushButton(tr(
"&Quit"
));
    
QVBoxLayout *vlayout=
new 
QVBoxLayout();
    
vlayout->addWidget(findButton);
    
vlayout->addWidget(quitButton);
 
    
matchBox=
new 
QCheckBox(tr(
"Match &Case"
));
    
searchBox=
new 
QCheckBox(tr(
"Search &Backword"
));
    
QVBoxLayout *vlayout1=
new 
QVBoxLayout();
    
vlayout1->addWidget(matchBox);
    
vlayout1->addWidget(searchBox);
 
    
QHBoxLayout *mainLayout=
new 
QHBoxLayout();
    
mainLayout->addLayout(hlayout);
    
mainLayout->addLayout(vlayout);
    
mainLayout->addLayout(vlayout1);
    
setLayout(mainLayout);
 
    
setWindowTitle(tr(
"Find"
));
    
setFixedHeight(sizeHint().height());
 
    
connect(textLine,SIGNAL(textChanged(
const 
QString &)),
this
,SLOT(enableFindButton(
const 
QString&)));
    
connect(findButton,SIGNAL(clicked()),
this
,SLOT(findClicked()));
    
connect(quitButton,SIGNAL(clicked()),
this
,SLOT(close()));
}
 
Find::~Find()
{
 
}
 
// void Find::findNext1(const QString &str,Qt::CaseSensitivity cs){
//     //do something here
// }
//
// void Find::findPrevious1(const QString &str,Qt::CaseSensitivity){
//            //do something here
// }
 
void 
Find::findClicked(){
    
QString text=textLine->text();
    
Qt::CaseSensitivity cs=matchBox->isChecked() ? Qt::CaseSensitive:Qt::CaseInsensitive;
    
if
(searchBox->isChecked()){
        
emit findPrevious1(text,cs);
    
}
else
{
        
emit findNext1(text,cs);
    
}
}
 
void 
Find::enableFindButton(
const 
QString &str){
    
findButton->setEnabled(!(str.isEmpty()));
}

 main.cpp

1
2
3
4
5
6
7
8
9
10
#include "find.h"
#include <QtGui/QApplication>
 
int 
main(
int 
argc, 
char 
*argv[])
{
    
QApplication a(argc, argv);
    
Find w=
new 
Find();
    
w.show();
    
return 
a.exec();
}

 

转载地址:http://oubbl.baihongyu.com/

你可能感兴趣的文章
协议中UART的两种模式 【转】
查看>>
SharePoint 2013 Farm 安装指南——Least Privilege
查看>>
C# 温故知新 基础篇(1) C#概述
查看>>
jQuery结合lhgdialog弹出窗口,关闭时出现没有权限错误
查看>>
EXTJS学习系列提高篇:第二十八篇(转载)作者殷良胜,ext2.2打造Ext.form.ComboBox系列--分页显示...
查看>>
如何完成.Net下XML文档的读写操作
查看>>
QTP的那些事--对已经存在Excel文件修改后保存时,会弹出一个询问对话框
查看>>
UVA 11174 Stand in a Line 树dp+算
查看>>
C语言中函数strcpy ,strncpy ,strlcpy的用法【转】
查看>>
mysql join 的同时可以筛选数据
查看>>
Code First开发系列之管理并发和事务
查看>>
Spark SQL概念学习系列之为什么使用 Spark SQL?(二)
查看>>
VirtualBox-Linux系统安装增强功能
查看>>
ssh/ssh2登录
查看>>
mongodb对数组元素及内嵌文档进行增删改查操作(转)
查看>>
【python3.5】安装lxml中没有etree模块的问题解决方法
查看>>
pgpool-II的性能缺陷
查看>>
spin_lock浅析【转】
查看>>
MVC前台Post/Get异步获得数据时参数的取值问题
查看>>
8086/8088指令详解
查看>>