[view] fix: several issues related to resizing

This commit is contained in:
Vinicius Moreira
2022-11-04 17:53:05 -03:00
parent 96d38f3b7f
commit de8b143273
8 changed files with 111 additions and 60 deletions

View File

@@ -1,16 +1,18 @@
from PyQt5.QtCore import Qt
from typing import Optional, Union
from PyQt5.QtCore import Qt, QRect, QPoint
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtWidgets import QWidget, QApplication, QDesktopWidget
from bauh.view.util import resource
desktop: Optional[QDesktopWidget] = None
def centralize(widget: QWidget):
geo = widget.frameGeometry()
screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos())
center_point = QApplication.desktop().screenGeometry(screen).center()
geo.moveCenter(center_point)
widget.move(geo.topLeft())
screen_geometry = get_current_screen_geometry()
widget.frameGeometry().moveCenter(screen_geometry.center())
widget.move(widget.frameGeometry().topLeft())
def load_icon(path: str, width: int, height: int = None) -> QIcon:
@@ -27,3 +29,13 @@ def measure_based_on_width(percent: float) -> int:
def measure_based_on_height(percent: float) -> int:
return round(percent * QApplication.primaryScreen().size().height())
def get_current_screen_geometry(source_widget: Optional[Union[QWidget, QPoint]] = None) -> QRect:
global desktop
if not desktop:
desktop = QDesktopWidget()
current_screen_idx = desktop.screenNumber(source_widget if source_widget else desktop.cursor().pos())
return desktop.screen(current_screen_idx).geometry()