Skip to content

Commit

Permalink
prevent dialog from being positioned off-screen (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-iwasawa authored Oct 9, 2024
1 parent 5dd7cf1 commit d58cbcd
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 d58cbcd

Please sign in to comment.