Gui: create modal dialog on the heap if its parent widget is used in the property editor

For more details see: https://forum.freecadweb.org/viewtopic.php?f=23&t=70655
This commit is contained in:
wmayer
2022-10-22 18:36:52 +02:00
parent 916891c3fc
commit c5a7654285
2 changed files with 22 additions and 15 deletions

View File

@@ -1441,24 +1441,28 @@ void LabelEditor::setText(const QString& s)
void LabelEditor::changeText()
{
PropertyListDialog dlg(static_cast<int>(type), this);
dlg.setWindowTitle(tr("List"));
auto hboxLayout = new QVBoxLayout(&dlg);
auto buttonBox = new QDialogButtonBox(&dlg);
PropertyListDialog* dlg = new PropertyListDialog(static_cast<int>(type), this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setWindowTitle(tr("List"));
auto hboxLayout = new QVBoxLayout(dlg);
auto buttonBox = new QDialogButtonBox(dlg);
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
auto edit = new PropertyListEditor(&dlg);
auto edit = new PropertyListEditor(dlg);
edit->setPlainText(this->plainText);
hboxLayout->addWidget(edit);
hboxLayout->addWidget(buttonBox);
connect(buttonBox, SIGNAL(accepted()), &dlg, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), &dlg, SLOT(reject()));
if (dlg.exec() == QDialog::Accepted) {
connect(buttonBox, &QDialogButtonBox::accepted, dlg, &PropertyListDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, dlg, &PropertyListDialog::reject);
connect(dlg, &PropertyListDialog::accepted, this, [&] {
QString inputText = edit->toPlainText();
QString text = QString::fromLatin1("[%1]").arg(inputText);
lineEdit->setText(text);
}
});
dlg->exec();
}
/**

View File

@@ -1568,15 +1568,18 @@ VectorListWidget::VectorListWidget(int decimals, QWidget *parent)
void VectorListWidget::buttonClicked()
{
VectorListEditor dlg(decimals, this);
dlg.setValues(value().value<QList<Base::Vector3d>>());
VectorListEditor* dlg = new VectorListEditor(decimals, this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setValues(value().value<QList<Base::Vector3d>>());
QPoint p(0, 0);
p = this->mapToGlobal(p);
dlg.move(p);
if (dlg.exec() == QDialog::Accepted) {
QVariant data = QVariant::fromValue<QList<Base::Vector3d>>(dlg.getValues());
dlg->move(p);
connect(dlg, &VectorListEditor::accepted, this, [&] {
QVariant data = QVariant::fromValue<QList<Base::Vector3d>>(dlg->getValues());
setValue(data);
}
});
dlg->exec();
}
void VectorListWidget::showValue(const QVariant& d)