mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 20:04:15 +02:00
[view] fix: several issues related to resizing
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user