Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174371
  • 博文数量: 69
  • 博客积分: 2627
  • 博客等级: 少校
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-24 22:37
文章分类

全部博文(69)

文章存档

2017年(3)

2014年(1)

2013年(4)

2012年(6)

2011年(21)

2010年(15)

2009年(19)

我的朋友

分类: C/C++

2009-09-01 11:22:44

第二章 Create Dialogs

1. Subclassing QDialog
------------------------
QDialog.setCaption(tr("..."));

class FindDialog : public QDialog{
...
signals:
slots:
...
};

注意的地方:
有Q_OBJECT等宏的.h文件,moc工具会进行处理,重新生成.cpp文件.
要在输入文件(.h)文件中,在类定义前声明要使用的类,防止moc报错.

如下: (finddialog.h)

#include ...

class QCheckBox; //防止moc报错
class QLabel;
class QLineEdit;
class QPushButton;

class FindDialog : public QDialog{
Q_OBJECT
...
};

用到的各类成员:
QCheckBox *caseCheckBox=new QCheckBox(tr("xxx"))
caseCheckBox->isOn()
findButton->setDefault(true)
findButton->setEnabled(false)

QVBoxLayout:
  addWidget()
  addLayout()
  setMargin(11)
  setSpacing(6)
  addStretch(1);
QHBoxLayout:
  addWidget();
  addLayout()


发送信号: emit findPrev(text,caseSensitive);


2. Signals and Slots in Depth
-------------------------------
slot: 普通的C++函数, virtual, can be overloaded, can be public,protected,or private,
      and can be directly invoked like any other C++ member functions.
      the difference is that a slot can also be connected to a signal,

四特性:

 . One signal can be connected to many slots
    when the signal is emitted,the slots are called one after the other,in an arbitrary order.

 . Many signal can be connected to the same slot:
    when either signal is emitted, the slot is called.

 . 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.
    Apart from that,signal-signal connections are indistinguishable from signal-slot connections.
    (除此之外,signal-signal和signal-slot连接是没有区别的)

 . Connections can be removed:      
    disconnect(lcd,SIGNAL(overflow()),this,SLOT(handleMathError)));
    这很少需要,QT在一个对象被删除时,自动删除和这个对象相关的所有连接.


Qt's Meta-Object System
-------------------------
introspection(内省),支持运行时获得QObject子类的"meta-information"信息.
(是否类似于JAVA的反射机制?)


3. Rapid Dialog Design
------------------------
设计代码写在.ui中
函数的代码写在.ui.h中

菜单:
Tools/Set Buddy
Layout/Lay Out Horizontally
Layout/Lay Out Vertically
Layout/Adjust
Tools/Tab Order
Edit/Connection
Preview/Preview

基本上和VB差不多,就是画界面而已,编译由uic来完成.


4. Shape-Changing Dialogs
--------------------------
就是窗体的一部分按条件来显示和隐藏.
略.


阅读(486) | 评论(0) | 转发(0) |
0

上一篇:Qt 3 学习笔记 - 第一章

下一篇:m4 示例

给主人留下些什么吧!~~