Qt:快速设计对话框.   C++ GUI

来源:互联网 发布:js导出csv 编辑:程序博客网 时间:2024/05/17 10:08

创建对话框的基本步骤:

             1.创建并初始化子窗口部件.

             2.把子窗口部件放到布局中.

             3.设置Tab键顺序.

             4.建立信号-槽之间的链接关系.

             5.实现对话框中的自定义槽.

Qt:快速设计对话框. <wbr> <wbr> <wbr>C++ <wbr>GUI


选择Create模板

设置每一个窗口部件中的属性:

1.单击文本标签 , objectName属性改为:"label" ,text属性改为:"&Cell Location"

2.单击行编辑器 , object属性改为:"lineEdit".

3.设置一个按钮 , object: "okButton" , enabled: "false" , text:"OK" , default: "true"

4.设置一个按钮 , object: "cancelButton" ,text:"Cancel"

5.单击窗体空白处 , object: "GoToCellDialog" , windowTitle: "Goto Cell"

6. Edit - > EditBuddies   单击标签把红色箭头拖到行编辑器上.   Edit -> Edit Widgets

 

摆放窗体部件步骤:

1.单击“Cenll Location” 和行编辑器(同时选上两个)   单击 from -> Lay Out Horizontally

2.选手分隔符 , OK按钮 和 Cancel按钮  单击 from -> Lay Out Horizontally

3.单击窗体空白处,单击 from - > Lay OutVertically

4.单击Form - > Adjust Size把窗体大小设为最佳.

5.Eidt - > Edit Tab Order设置Tab键的顺序.

保存gotocell目录下 , 文件名位:gotocelldialog.ui

 

gotocelldialog.h如下:

#include<QDialog>
#include"ui_gotocelldialog.h"

class GoToCellDialog : public QDialog ,public Ui::GoToCellDialog
{
 Q_OBJECT
public:
 GoToCellDialog(QWidget*parent = 0);
private slots:
 voidon_lineEdit_textChanged();
};

 

gotocelldialog.cpp 如下:

#include<QtGui>
#include"gotocelldialog.h"

GoToCellDialog::GoToCellDialog(QWidget*parent) : QDialog(parent)
{
 setupUi(this);
 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

 QRegExpregExp("[A-Za-z][1-9][0-9]{0,2}");
 lineEdit->setValidator(newQRegExpValidator(regExp , this));

 connect(buttonBox,SIGNAL(accepted()) , this , SLOT(accept()) );
 connect(buttonBox ,SIGNAL(rejected()) , this , SLOT(reject()) );
}

voidGoToCellDialog::on_lineEdit_textChanged()
{
 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(lineEdit->hasAcceptableInput());
}

 

main.cpp 如下:

#include<QApplication>
#include"gotocelldialog.h"

int main(int argc , char*argv[])
{
 QApplication app(argc ,argv);
 GoToCellDialog *dialog= new GoToCellDialog;
 dialog->show();

 returnapp.exec();
}

结果如图:

Qt:快速设计对话框. <wbr> <wbr> <wbr>C++ <wbr>GUI

0 0