第二章 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
--------------------------
就是窗体的一部分按条件来显示和隐藏.
略.
阅读(497) | 评论(0) | 转发(0) |