mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 06:37:17 +00:00
Add windows position handling at open, fix #653
- Move offscreen windows back on screen - Restore maximized state without impacting resored size - Fullscreen comes back on primary screen, needs further work to support restore on other screens
This commit is contained in:
@@ -18,6 +18,7 @@ from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
)
|
||||
|
||||
from qtlib.util import move_to_screen_center
|
||||
from hscommon.trans import trget
|
||||
|
||||
tr = trget("qtlib")
|
||||
@@ -71,6 +72,11 @@ class AboutBox(QDialog):
|
||||
self.verticalLayout.addWidget(self.buttonBox)
|
||||
self.horizontalLayout.addLayout(self.verticalLayout)
|
||||
|
||||
def showEvent(self, event):
|
||||
# have to do this here as the frameGeometry is not correct until shown
|
||||
move_to_screen_center(self)
|
||||
super().showEvent(event)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
@@ -16,9 +16,8 @@ from core.util import executable_folder
|
||||
from hscommon.util import first
|
||||
|
||||
from PyQt5.QtCore import QStandardPaths
|
||||
from PyQt5.QtGui import QPixmap, QIcon
|
||||
from PyQt5.QtGui import QPixmap, QIcon, QGuiApplication
|
||||
from PyQt5.QtWidgets import (
|
||||
QDesktopWidget,
|
||||
QSpacerItem,
|
||||
QSizePolicy,
|
||||
QAction,
|
||||
@@ -28,8 +27,19 @@ from PyQt5.QtWidgets import (
|
||||
|
||||
def move_to_screen_center(widget):
|
||||
frame = widget.frameGeometry()
|
||||
frame.moveCenter(QDesktopWidget().availableGeometry().center())
|
||||
widget.move(frame.topLeft())
|
||||
if QGuiApplication.screenAt(frame.center()) is None:
|
||||
# if center not on any screen use default screen
|
||||
screen = QGuiApplication.screens()[0].availableGeometry()
|
||||
else:
|
||||
screen = QGuiApplication.screenAt(frame.center()).availableGeometry()
|
||||
# moves to center of screen if partially off screen
|
||||
if screen.contains(frame) is False:
|
||||
# make sure the frame is not larger than screen
|
||||
# resize does not seem to take frame size into account (move does)
|
||||
widget.resize(frame.size().boundedTo(screen.size() - (frame.size() - widget.size())))
|
||||
frame = widget.frameGeometry()
|
||||
frame.moveCenter(screen.center())
|
||||
widget.move(frame.topLeft())
|
||||
|
||||
|
||||
def vertical_spacer(size=None):
|
||||
|
||||
Reference in New Issue
Block a user