Creating Dialogs
#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的更多相关文章
- 30个惊人的插件来扩展 Twitter Bootstrap
Bootstrap Maxlength It is a lightweight plugin that allows detecting the HTML maxlength property of ...
- qt 总结
Qt中的每个类,都有一个对应的同名头文件,其中包含其类定义.例如要使用QApplication类,则需要在程序中添加" #include <QApplication>" ...
- RFC3261--sip
本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...
- Andorid API Package ---> android.app
包名: android.app Added in API level 1 URL:http://developer. ...
- Qt qml的软件架构设计
google: qt qml application architecture 有很多资源. 1 https://www.ics.com/blog/multilayered-architecture- ...
- FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框
FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...
- SharePoint 2010 Pop-Up Dialogs
转:http://kyleschaeffer.com/sharepoint/sharepoint-2010-pop-up-dialogs/ SharePoint 2010 makes it incre ...
- [ARIA] Accessible modal dialogs
Learn how to create a modal dialog with accessible keyboard and screen reader mechanics using the na ...
- 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;
一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...
随机推荐
- 简单理解js的prototype属性
在进入正文之前,我得先说说我认识js的prototype这个东西的曲折过程. 百度js的prototype的文章,先看看,W3School关于prototype的介绍: 你觉得这概念适合定义js的pr ...
- centos7 web服务器内核优化
net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_keepalive_time = 600net.ipv4 ...
- ios监听键盘弹出 频幕位置改变
- TT3
crm_kfs_fy 房源 dk_sq_cs 申请测算 dk_zh 贷款账户 dk_ht 借款合同 SS_DICT_MX 数据字典明细 ...
- JFinal学习
1 jfinal-1.9-bin.jar 2 继承Controller编写控制器 public void sendJPushToXXX() { String userId = getPara(&quo ...
- 关于sigwait
刚开始看sigwait函数,只是知道它是用来解除阻塞的信号,可是使我疑惑的是那么解除了以后为什么线程收到终止信号SIGINT的时候还是没能终止呢? 于是网上找了一些资料,总的理解如下所示: sig ...
- Windows Phone 八、文件读写IO
文件存储的类型 •本地应用文件: •ApplicationData.Current.LocalFolder: •漫游应用文件: •ApplicationData.Current.RoamingFold ...
- Linux 环境变量PS1设置
新建用户不显示IP和机器名 CentOS下新增加一个用户,登录进去会发现shell脚本信息没有显示用户名和主机名,反而显示的是user1@202.173.1.12 解决方案: 1.在新建用户的-目录下 ...
- css2 [lang|=en] 误区
[lang|=en] w3c说明:css2选择器,选择以en开头的的lang属性. w3c的这个解释是有误区的,en开头,但是en后面必须要有-,也就是说是选择的是en-开头
- 删除txt文件每行第一(n)个空格前内容的方法
1. 把要处理的文本保存在a.txt文件中 2. 在相同文件夹中新建一个xx.txt文件,输入下面代码,再把文件名改为xx.bat. @echo offset fn=a.txt(for /f &quo ...