Skip to content

Commit 210425f

Browse files
committed
Adds attributes for controlling the window created via dialog()
Fixes #2947
1 parent 5956bcb commit 210425f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

docs/scripting-api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,10 @@ unlike in GUI, where row numbers start from 1 by default.
10991099
- '.style' - Qt style sheet for dialog
11001100
- '.height', '.width', '.x', '.y' - dialog geometry
11011101
- '.label' - dialog message (can contain basic HTML)
1102+
- '.modal' - set to true to make the dialog modal (to avoid other windows to get input focus)
1103+
- '.onTop' - set to true for the dialog to stay above other windows
1104+
- '.noParent' - set to true to avoid attaching the dialog to the main window
1105+
- '.popupWindow', '.sheetWindow', '.toolWindow', '.foreignWindow' - set/unset the type of dialog window (see `Qt::WindowFlags <https://doc.qt.io/qt-6/qt.html#WindowType-enum>`__ for details)
11021106

11031107
:returns: Value or values from accepted dialog or ``undefined`` if dialog
11041108
was canceled.

src/scriptable/scriptableproxy.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,20 @@ int ScriptableProxy::inputDialog(const NamedValueList &values)
20822082
createAndSetWidget<QLabel>("text", value.value, &dialog);
20832083
else if (value.name == ".defaultChoice")
20842084
inputDialog.defaultChoice = value.value.toString();
2085+
else if (value.name == ".modal")
2086+
dialog.setModal(value.value.toBool());
2087+
else if (value.name == ".onTop")
2088+
dialog.setWindowFlag(Qt::WindowStaysOnTopHint, value.value.toBool());
2089+
else if (value.name == ".noParent")
2090+
dialog.setParent(value.value.toBool() ? nullptr : m_wnd);
2091+
else if (value.name == ".popupWindow")
2092+
dialog.setWindowFlag(Qt::Popup, value.value.toBool());
2093+
else if (value.name == ".toolWindow")
2094+
dialog.setWindowFlag(Qt::Tool, value.value.toBool());
2095+
else if (value.name == ".sheetWindow")
2096+
dialog.setWindowFlag(Qt::Sheet, value.value.toBool());
2097+
else if (value.name == ".foreignWindow")
2098+
dialog.setWindowFlag(Qt::ForeignWindow, value.value.toBool());
20852099
else
20862100
widgets.append( createWidget(value.name, value.value, &inputDialog) );
20872101
}

src/tests/tests_scripts.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,25 @@ void Tests::commandDialog()
376376
[&]() { RUN(WITH_TIMEOUT "dialog('.title', 'Remove Items', '.label', 'Remove all items?') === true", "true\n"); },
377377
[&]() { RUN(Args() << "keys" << "focus::QPushButton in dialog_Remove Items:QDialog" << "ENTER", ""); }
378378
);
379+
380+
RUN(Args() << "keys" << clipboardBrowserId, "");
381+
const QByteArray script2 = R"(
382+
dialog(
383+
'.modal', true,
384+
'.onTop', true,
385+
'.noParent', true,
386+
'.popupWindow', true,
387+
'.toolWindow', true,
388+
'.sheetWindow', false,
389+
'.foreignWindow', true,
390+
'.noParent', true,
391+
'text', 'DEFAULT',
392+
)
393+
)";
394+
runMultiple(
395+
[&]() { RUN(WITH_TIMEOUT + script2, "DEFAULT\n"); },
396+
[&]() { RUN(Args() << "keys" << "focus::QLineEdit in :QDialog" << "ENTER", ""); }
397+
);
379398
}
380399

381400
void Tests::commandDialogCloseOnDisconnect()

0 commit comments

Comments
 (0)