#ifndef DIALOG_H
#define DIALOG_H #include <QtWidgets>
//#include <QDialog>
//#include <QLabel>
//#include <QCheckBox>
//#include <QLineEdit>
//#include <QPushButton>
//#include <QtCore>
namespace Ui {
class Dialog;
} class Dialog : public QDialog
{
Q_OBJECT public:
explicit Dialog(QWidget *parent = );
~Dialog(); signals:
void FindNext(const QString &str, Qt::CaseSensitivity cs);
void FindPre (const QString &str, Qt::CaseSensitivity cs); private slots:
void FindClicked();
void EnabledFindButton(const QString &text); private:
Ui::Dialog *ui;
QLabel *label;
QLineEdit *lineEdit;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QPushButton *findButton;
QPushButton *closeButton;
}; #endif // DIALOG_H

dialog.h

#include "dialog.h"
#include "ui_dialog.h" Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
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(EnabledFindButton(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 Dialog::FindClicked()
{
QString text = lineEdit->text();
Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;
if(backwardCheckBox->isChecked())
{
emit FindPre(text,cs);
}
else
emit FindNext(text,cs); } void Dialog::EnabledFindButton(const QString &text)
{
findButton->setEnabled(!text.isEmpty());
} Dialog::~Dialog()
{
delete ui;
}

dialog.cpp

#include "dialog.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show(); return a.exec();
}

main.cpp

1、对于定义了信号(signals)或槽(slots)的类,宏定义Q_OBJECT是必须的

2、tr(),翻译可显字符

3、‘&’表示快捷键

4、setDefault(true) 设置default按钮(按回车即为按下该按钮)

5、setEnabled(false) 设置按钮无效,按钮显示为灰色

6、setWindowTitle(tr("Find"));

setFixedHeight(sizeHint().height()); //程序自己设置一个合适的高度

7、connect(sender,SIGNAL(signal),receiver,SLOT(slot));

QLabel *label = new QLabel;
QScrollBar *scrollBar = new QScrollBar;
QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));

  This example ensures that the label always displays the current scroll bar value. Note that the signal and slots parameters must not   contain any variable names, only the type. E.g. the following would not work and return false:

// WRONG
QObject::connect(scrollBar, SIGNAL(valueChanged(int value)),
label, SLOT(setNum(int value)));

  a signal can be connected to another signal

connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SIGNAL(updateRecord(const QString &)));

  when the first signal is emitted, the second signal is emitted as well.

  To successfully connect a signal to a slot (or to another signal), they must have the same parameter types in the same order:

connect(ftp, SIGNAL(rawCommandReply(int, const QString &)), this , SLOT(processReply(int, const QString &)));

Creating Dialogs的更多相关文章

  1. 30个惊人的插件来扩展 Twitter Bootstrap

    Bootstrap Maxlength It is a lightweight plugin that allows detecting the HTML maxlength property of ...

  2. qt 总结

    Qt中的每个类,都有一个对应的同名头文件,其中包含其类定义.例如要使用QApplication类,则需要在程序中添加" #include <QApplication>" ...

  3. RFC3261--sip

    本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...

  4. Andorid API Package ---> android.app

    包名: android.app                                     Added in API level 1       URL:http://developer. ...

  5. Qt qml的软件架构设计

    google: qt qml application architecture 有很多资源. 1 https://www.ics.com/blog/multilayered-architecture- ...

  6. FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框

    FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...

  7. SharePoint 2010 Pop-Up Dialogs

    转:http://kyleschaeffer.com/sharepoint/sharepoint-2010-pop-up-dialogs/ SharePoint 2010 makes it incre ...

  8. [ARIA] Accessible modal dialogs

    Learn how to create a modal dialog with accessible keyboard and screen reader mechanics using the na ...

  9. 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;

    一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...

随机推荐

  1. Livermore心法--策略篇

    「三三不尽,六六无穷」就是Livermore选股法的精要,以6%设关键位,3%定突破. 可是,在买卖策略方面,却不能光靠看突破就随便买入. 以Livermore的讲法,通常一只股突破前关键位后,会有轻 ...

  2. ASP.NET MVC location.href不跳转

    表单使用submit导致不跳转 <button type="button">

  3. u-boot FIT image介绍_转自“蜗窝科技”

    转自:http://www.wowotech.net/u-boot/fit_image_overview.html 1. 前言 Linux kernel在ARM架构中引入设备树device tree( ...

  4. Docker应用程序容器技术_转

    转自:百度百科 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相 ...

  5. python 调用封装好的模块

    有些时候,我们写了些通用的模块,想调用的时候,该怎么操作呢? 以下是我写的一个简单的登录作为例子: 在cla.py中定义了一个Login_gues.pyt(带参数的实例):在cc.py下调用这个; 1 ...

  6. No Spring WebApplicationInitializer types detected on classpath。启动时不报错,但是页面打不开。

    一片红,没有黑色disPatcher的加载. 百度,但是没有用,二十分钟浪费,这个问题的本质就是web.xml中的disPatcher没有加载,但是我肯定和代码无关,配置文件也没有变化过,值可能是to ...

  7. XPath 运算符

    XPath 表达式可返回节点集.字符串.逻辑值以及数字. XPath 运算符 下面列出了可用在 XPath 表达式中的运算符: 运算符 描述 实例 返回值 | 计算两个节点集 //book | //c ...

  8. CentOS双网卡绑定bond0

    a)拷⻉并配置vim /etc/sysconfig/network-scripts/ifcfg-bond0配置⽂件(会自动创建文件) DEVICE=bond0 TYPE=Ethernet ONBOOT ...

  9. 用于 Linux 平台的 Java

    切换到所需的安装目录.键入:cd directory_path_name例如,要将软件安装到 /usr/java/ 目录中,请键入:cd /usr/java/ 将 .tar.gz 档案二进制文件移到当 ...

  10. JAVA 学习随笔 : JDK Enhancement Process JEP process

    是时候寻找一个学习JAVA的路径了 ---- JDK Enhancement Process Oracle发布了JDK增强提案与路线图进程,目的在于鼓励OpenJDK提交者贡献点子和扩展以改进Open ...