#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. JAVASE02-Unit05: 集合操作 —— 查找表

    Unit05: 集合操作 -- 查找表 使用该类测试自定义元素的集合排序 package day05; /** * 使用该类测试自定义元素的集合排序 * @author adminitartor * ...

  2. Jesse Livermore的21句投机至理名言

    1.优秀的投机家们总是在等待,总是有耐心,等待着市场证实他们的判断.要记住,在市场本身的表现证实你的看法之前,不要完全相信你的判断.        2.要想在投机中赚到钱,就得买卖一开始就表现出利润的 ...

  3. sed处理url编码解码=== web日志的url处理

    URL 编码/解码方法(linux  shell实现),方法如下: 1.编码的两种方法: admin@~ 11:14:29>echo '手机' | tr -d '\n' | xxd -plain ...

  4. Python之路-(js正则表达式、前端页面的模板套用、Django基础)

    js正则表达式 前端页面的模板套用 Django基础 js正则表达式: 1.定义正则表达式 /.../  用于定义正则表达式 /.../g 表示全局匹配 /.../i 表示不区分大小写 /.../m ...

  5. python成长之路-----day1----笔记(1)

    1.python语言介绍 python的创始人:Guido Van Rossum 2.python是一门什么样的语言 编程语言主要从以下几个角度进行分类:编译型,静态型,动态性,强类型定义语言和弱类型 ...

  6. NOI 05:最高的分数描述

    描述 孙老师讲授的<计算概论>这门课期中考试刚刚结束,他想知道考试中取得的最高分数.因为人数比较多,他觉得这件事情交给计算机来做比较方便.你能帮孙老师解决这个问题吗? 输入输入两行,第一行 ...

  7. DIY PIXHAWK APM等飞控用的PPM转接板

    需要的硬件 一块arduino pro mini(推荐这个,比较小,当然如果你没有USB转转口的烧写工具买个ardunio nano板也是不错的,直接用USB线连接电脑就可以,用nano板要注意.它的 ...

  8. com.caucho.hessian.io.HessianProtocolException: is unknown code 解决方案

    问题: Cannot access Hessian remote service at [http://....../remote/syllabusService]; nested exception ...

  9. java方法与构造

    public class StaticClass { static int i = 50; int y; // 构造只能有访问修饰符public.protected.private 修饰 (访问修饰符 ...

  10. XEN的启动信息输出到“Platform timer is 14.318MHz HPET”就暂停接收的解决办法

    使用Serial Over Lan(SOL)来双机调试 XEN,在 XEN 启动时,引导信息输出到以下这一句时,就不再发送调试信息了: ...(XEN) Intel machine check rep ...