From 544cfb9e3c050ef9333286f8d6cd75117605b890 Mon Sep 17 00:00:00 2001 From: "Chris Rapson (AT)" <4982550+chrisrapson@users.noreply.github.com> Date: Mon, 24 Aug 2020 14:12:44 +1200 Subject: [PATCH] adjust position of popup labelDialog to make sure it is within edge of main window --- libs/labelDialog.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/labelDialog.py b/libs/labelDialog.py index b59de084..924a4a8d 100644 --- a/libs/labelDialog.py +++ b/libs/labelDialog.py @@ -67,7 +67,16 @@ class LabelDialog(QDialog): self.edit.setSelection(0, len(text)) self.edit.setFocus(Qt.PopupFocusReason) if move: - self.move(QCursor.pos()) + cursor_pos = QCursor.pos() + parent_bottomRight = self.parentWidget().geometry() + max_x = parent_bottomRight.x() + parent_bottomRight.width() - self.sizeHint().width() + max_y = parent_bottomRight.y() + parent_bottomRight.height() - self.sizeHint().height() + max_global = self.parentWidget().mapToGlobal(QPoint(max_x, max_y)) + if cursor_pos.x() > max_global.x(): + cursor_pos.setX(max_global.x()) + if cursor_pos.y() > max_global.y(): + cursor_pos.setY(max_global.y()) + self.move(cursor_pos) return self.edit.text() if self.exec_() else None def listItemClick(self, tQListWidgetItem):