AECSoft

专注于AEC行业软件开发15年

导航

方便快捷地使用QDialog显示小对话框

    QDialog dlg(this);
    QLabel *label = new QLabel("名称:");
    QLineEdit *lineEdit = new QLineEdit();
    label->setBuddy(lineEdit);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(
               QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    connect(buttonBox, SIGNAL(accepted()), &dlg, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), &dlg, SLOT(reject()));

    QGridLayout *gridLayout = new QGridLayout;
    gridLayout->addWidget(label, 0, 0);
    gridLayout->addWidget(lineEdit, 0, 1);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(gridLayout);
    mainLayout->addWidget(buttonBox);
    dlg.setLayout(mainLayout);

    dlg.setWindowTitle("对话框名称");

    if(dlg.exec() == QDialog::Accepted)
    {
        QString name = lineEdit->text();
        //,,,
    }

 

posted on 2013-03-25 22:18  zuoc  阅读(542)  评论(0编辑  收藏  举报