快速设计对话框3

使用QDialogButtonBox来制作这个对话框,它是一个可以容纳给定按钮的窗口部件,可以让那些按钮以正确方式呈现在应用程序所运行的平台上

 

在之前的.ui上面单击窗体,然后Form->Break Layout,删除ok和cancel按钮以及水平分隔符

拖放一个“按钮盒”(Button Box),单机窗体,然后Form->Lay Out Vertically

 

gotocelldialog.cpp

#include <QtGui>

#include "gotocelldialog.h"

GoToCellDialog::GoToCellDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);
    buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);  //得到QDialogButtonBox的按钮方法

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

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

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

 

附加小知识:

1:QdialogButtonBox::Ok按钮具有AcceptRole属性,在单击一个带AcceptRole的按钮时,就会发射accepted()信号

 

运行效果:

 

posted on 2013-01-04 11:06  小风儿_xf  阅读(185)  评论(0编辑  收藏  举报

导航