本文整理汇总了C++中QDialog::accept方法的典型用法代码示例。如果您正苦于以下问题:C++ QDialog::accept方法的具体用法?C++ QDialog::accept怎么用?C++ QDialog::accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDialog
的用法示例。
在下文中一共展示了QDialog::accept方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDialog
QString AddImagesDialog::getDirectory(const QStringList &fileNames, const QString &defaultDirectory)
{
QDialog *dialog = new QDialog(Core::ICore::dialogParent());
dialog->setMinimumWidth(480);
QString result;
QString directory = defaultDirectory;
dialog->setModal(true);
dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
dialog->setWindowTitle(QCoreApplication::translate("AddImageToResources","Add Resources"));
QTableWidget *table = createFilesTable(fileNames);
table->setParent(dialog);
QGridLayout *mainLayout = new QGridLayout(dialog);
mainLayout->addWidget(table, 0, 0, 1, 4);
QComboBox *directoryComboBox = createDirectoryComboBox(defaultDirectory);
auto setDirectoryForComboBox = [directoryComboBox, &directory](const QString &newDir) {
if (directoryComboBox->findText(newDir) < 0)
directoryComboBox->addItem(newDir);
directoryComboBox->setCurrentText(newDir);
directory = newDir;
};
QObject::connect(directoryComboBox, &QComboBox::currentTextChanged, dialog, [&directory](const QString &text){
directory = text;
});
QPushButton *browseButton = new QPushButton(QCoreApplication::translate("AddImageToResources", "&Browse..."), dialog);
QObject::connect(browseButton, &QPushButton::clicked, dialog, [setDirectoryForComboBox, &directory]() {
const QString newDir = QFileDialog::getExistingDirectory(Core::ICore::dialogParent(),
QCoreApplication::translate("AddImageToResources", "Target Directory"),
directory);
if (!newDir.isEmpty())
setDirectoryForComboBox(newDir);
});
mainLayout->addWidget(new QLabel(QCoreApplication::translate("AddImageToResources", "In directory:")), 1, 0);
mainLayout->addWidget(directoryComboBox, 1, 0, 1, 3);
mainLayout->addWidget(browseButton, 1, 3, 1 , 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
mainLayout->addWidget(buttonBox, 3, 2, 1, 2);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, dialog, [dialog](){
dialog->accept();
dialog->deleteLater();
});
QObject::connect(buttonBox, &QDialogButtonBox::rejected, dialog, [dialog, &directory](){
dialog->reject();
dialog->deleteLater();
directory = QString();
});
QObject::connect(dialog, &QDialog::accepted, [&directory, &result](){
result = directory;
});
dialog->exec();
return result;
}