1 Star 0 Fork 4

latte79/spreadsheet

forked from EarlDoss/spreadsheet 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
finddialog.cpp 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
#include "finddialog.h"
/* 1.创建并初始化子窗口部件
* 2.把子窗口放到布局中
* 3.设置Tab键顺序
* 4.建立信号-槽之间的连接
* 5.实现对话框中的自定义槽
*/
#include<QtWidgets> //Qt最重要的头文件
FindDialog::FindDialog(QWidget*parent):QDialog(parent) //把parent参数传递给基类构造函数
{
/*********1.创建并初始化子窗口部件**********************/
label=new QLabel(tr("找什么(&W)")); //字符串调用tr函数,翻译成其他语言标记
lineEdit=new QLineEdit;
label->setBuddy(lineEdit); //使用快捷键w将光标放在文本框里
caseCheckBox =new QCheckBox(tr("区分大小写(&C)"));
backwardCheckBox=new QCheckBox(tr("向后查找(&B)"));
findButton =new QPushButton(tr("开始查找(&F)"));
closeButton=new QPushButton(tr("关闭"));
findButton->setDefault(true);
findButton->setEnabled(false);
/*********4.建立信号-槽之间地连接**********************/
connect(lineEdit,SIGNAL(textChanged(QString)), //信号和槽的参数是同一个
this,SLOT(enabledFindButton(QString)));
connect(findButton,SIGNAL(clicked()),
this,SLOT(findClicked()));
connect(closeButton,SIGNAL(clicked()),
this,SLOT(close()));
/*********2.把子窗口放到布局中**********************/
//一个布局就是一个盒子
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);
this->setLayout(mainLayout);
this->setWindowTitle(tr("查找对话框"));
this->setFixedHeight(sizeHint().height()); //创建最佳高度
}
void FindDialog::enabledFindButton(const QString &text)
{
findButton->setEnabled(!text.isEmpty());
}
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);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/latte79/spreadsheet.git
git@gitee.com:latte79/spreadsheet.git
latte79
spreadsheet
spreadsheet
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385