北京大学软件学院模板-IntelSoftware.ppt

* * * * * * * * * * * * * * * * * * 查找对话框示例 1 #include QtGui 2 #include finddialog.h 3 FindDialog::FindDialog(QWidget *parent) 4 : QDialog(parent) 5 { 6 label = new QLabel(tr(Find what:)); 7 lineEdit = new QLineEdit; 8 label-setBuddy(lineEdit); 9 caseCheckBox = new QCheckBox(tr(Match case)); 10 backwardCheckBox = new QCheckBox(tr(Search backward)); 11 findButton = new QPushButton(tr(Find)); 12 findButton-setDefault(true); 13 findButton-setEnabled(false); 14 closeButton = new QPushButton(tr(Close)); 查找对话框示例 15 connect(lineEdit, SIGNAL(textChanged(const QString )), 16 this, SLOT(enableFindButton(const QString ))); 17 connect(findButton, SIGNAL(clicked()), 18 this, SLOT(findClicked())); 19 connect(closeButton, SIGNAL(clicked()), 20 this, SLOT(close())); 查找对话框示例 通过connect函数实现了信号和槽的连接 只要行编辑器中的文本发生变化,就会调用私有槽enableFindButton 当用户单击Find按钮时,会调用findClicked私有槽 当用户单击Close时,对话框关闭 查找对话框示例 21 QHBoxLayout *topLeftLayout = new QHBoxLayout; 22 topLeftLayout-addWidget(label); 23 topLeftLayout-addWidget(lineEdit); 24 QVBoxLayout *leftLayout = new QVBoxLayout; 25 leftLayout-addLayout(topLeftLayout); 26 leftLayout-addWidget(caseCheckBox); 27 leftLayout-addWidget(backwardCheckBox); 28 QVBoxLayout *rightLayout = new QVBoxLayout; 29 rightLayout-addWidget(findButton); 30 rightLayout-addWidget(closeButton); 31 rightLayout-addStretch(); 32 QHBoxLayout *mainLayout = new QHBoxLayout; 33 mainLayout-addLayout(leftLayout); 34 mainLayout-addLayout(rightLayout); 35 setLayout(mainLayout); 36 setWindowTitle(tr(Find)); 37 setFixedHeight(sizeHint().height()); 38 } 查找对话框示例 Qt提供了布局管理器布局子窗口部件 通过QHBoxLayout,QVBoxLayout和QGridLayout这三个布局的不同嵌套组合,就可以构建出相当复杂的对话框。 查找对话框示例 39 void FindDialog::findClicked() 40 { 41 QString text = lineEdit-text(); 42 Qt::CaseSensitivity cs = 43 caseCheckBox-isChecked() ? Qt::CaseSensitive :Qt::CaseInsensitive; 44 if (backwardCheckBo

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档