Skip to content

Commit

Permalink
Set main window as parent when starting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinmo committed Jun 12, 2019
1 parent 426f866 commit 4f0eff3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion palette/src/palette_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ static void postToThread2(F&& fun, QThread* thread = qApp->thread()) {
Qt::QueuedConnection);
}

QWidget* getMainWindow() {
// This is not too expensive.
for (auto& widget : qApp->topLevelWidgets()) {
if (qobject_cast<QMainWindow*>(widget)) {
return widget;
}
}
return nullptr;
}

void show_palette(const QString& name, const QString& placeholder, const QVector<Action>& actions, const QString& closeKey, ActionHandler func) {
postToThread2([=]() {
g_current_widget = new CommandPalette();
g_current_widget = new CommandPalette(getMainWindow());
g_current_widget->show(name, placeholder, actions, closeKey, std::move(func));
});
}
Expand Down

0 comments on commit 4f0eff3

Please sign in to comment.