def on_screen_changed(self, screen: QScreen): self._factor = screen.devicePixelRatio() self.engine.pixel_factor = self._factor # force an update and reset of viewport's dimensions self.resizeGL(self.geometry().width() * self._factor, self.geometry().height() * self._factor)
def centerPositionWindow(self): self.ui.frame_workingSpace.show() screen = QScreen.geometry(QGuiApplication.primaryScreen()) widthHalf, heightHalf = self.sizePercentOfScreen(0.5, 0.5) self.setGeometry( QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, QSize(widthHalf, heightHalf), screen)) self.setFixedSize(widthHalf, heightHalf)
def sizePercentOfScreen(self, aplhaWindth: float, aplhaHeight: float) -> Tuple[int, int]: """ Initiate size and location of window """ screen = QScreen.availableSize(QGuiApplication.primaryScreen()) windowWidth = (screen.width()) * aplhaWindth windowHeight = (screen.height()) * aplhaHeight return windowWidth, windowHeight
def initGeometryWindow(self, aplhaPosX: float, aplhaPosY: float, aplhaWindth: float, aplhaHeight: float) -> None: """ Initiate size and location of window """ screen = QScreen.availableSize(QGuiApplication.primaryScreen()) pos_x = (screen.width()) * aplhaPosX pos_y = (screen.height()) * aplhaPosY windowWidth = (screen.width()) * aplhaWindth windowHeight = (screen.height()) * aplhaHeight self.setGeometry(pos_x, pos_y, windowWidth, windowHeight) self.setFixedSize(windowWidth, windowHeight)
def startProgram(self, page): screen = QScreen.availableSize(QGuiApplication.primaryScreen()) if ((self.geometry().width()) / (screen.width()) <= 0.05): self.expand() self.ui.stackedWidget.setCurrentWidget(page)
#!/usr/bin/env python3 import os import sys from PySide2.QtGui import QScreen from PySide2.QtWidgets import QApplication app = QApplication(sys.argv) screenshot = QScreen.grabWindow(app.desktop().winId()) screenshot.save(os.path.expanduser("~/screenshot.jpg"), "jpg")