Skip to content

Commit

Permalink
prevent dialog from being positioned off-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-iwasawa committed Oct 8, 2024
1 parent 5dd7cf1 commit 23548fb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sources/iwdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <QVariant>
#include <iostream>
#include <QGuiApplication>
#include <QScreen>

//---------------------------------------------------
// コンストラクタで、位置/サイズをロード
Expand Down Expand Up @@ -44,6 +46,13 @@ IwDialog::IwDialog(QWidget* parent, SettingsId dialogName, bool isResizable)
else {
m_geom = QRect(leftEdge, topEdge, 1, 1);
}

// スクリーン画面外の場合は、プライマリスクリーンの中心に持ってくる
QScreen* screen = QGuiApplication::screenAt(mapToGlobal(m_geom.center()));
if (!screen) {
m_geom.moveCenter(mapFromGlobal(
QGuiApplication::primaryScreen()->virtualGeometry().center()));
}
}

//---------------------------------------------------
Expand Down

0 comments on commit 23548fb

Please sign in to comment.