PySide2 как сделать вокруг прозрачной рамки фон?

Делаю небольшую прогу для скриншотов, есть прозрачная рамка, которой можно изменять размер с помощью мыши. Хочу сделать чтобы вокруг нее был затемненный полупрозрачный фон, но не знаю как...

Вот как есть: введите сюда описание изображения

А вот как надо: введите сюда описание изображения

Код:

# -*- coding: utf-8 -*-

# PySide2 импорты
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtWidgets import QApplication, QMainWindow, QWidget, QGridLayout
from PySide2.QtCore import Qt, QPoint, QRect, QSize


class Widget4(QMainWindow):
    def __init__(self):
        super().__init__()
        self.central = QWidget()

        self.setStyleSheet("border: 2px solid #ff0")
        self.setMinimumHeight(66)
        self.setMinimumWidth(66)
        self.vbox = QGridLayout(self.central)
        self.vbox.setSpacing(0)
        self.vbox.setContentsMargins(2, 2, 2, 2)
        
        # FLAGS
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.installEventFilter(self)

        self.press_control = 0

        self.setCentralWidget(self.central)
        self.resize(800, 500)
        self.update()

    def eventFilter(self, obj, e):
        #hovermoveevent
        if e.type() == 129:
            if self.press_control == 0:
                self.pos_control(e)#cursor position control for cursor shape setup
                self.update()

        #mousepressevent
        if e.type() == 2:
            self.press_control = 1
            self.origin = self.mapToGlobal(e.pos())
            self.ori_geo = self.geometry()

        #mousereleaseevent
        if e.type() == 3:
            self.press_control = 0
            self.pos_control(e)
            
        #mosuemoveevent
        if e.type() == 5:
            if self.cursor().shape() != Qt.ArrowCursor:
                self.resizing(self.origin, e, self.ori_geo, self.value)
                self.update()
                self.repaint()
                geom = self.geometry()
                self.setGeometry(geom.x(), geom.y(), geom.width(), geom.height()-1)
                self.repaint()

        return True

    def pos_control(self, e):
        rect = self.rect()
        top_left = rect.topLeft()
        top_right = rect.topRight()
        bottom_left = rect.bottomLeft()
        bottom_right = rect.bottomRight()
        pos = e.pos()

        #top catch
        if QRect(QPoint(top_left.x()+5,top_left.y()), QSize(top_right.x()-5,top_right.y()+5)).contains(pos):
            self.setCursor(Qt.SizeVerCursor)
            self.value = 1

        #bottom catch
        elif QRect(QPoint(bottom_left.x()+5,bottom_left.y()), QPoint(bottom_right.x()-5,bottom_right.y()-5)).contains(pos):
            self.setCursor(Qt.SizeVerCursor)
            self.value = 2
        
        #right catch
        elif QRect(QPoint(top_right.x()-5,top_right.y()+5), QPoint(bottom_right.x(),bottom_right.y()-5)).contains(pos):
            self.setCursor(Qt.SizeHorCursor)
            self.value = 3

        #left catch
        elif QRect(QPoint(top_left.x()+5,top_left.y()+5), QPoint(bottom_left.x(),bottom_left.y()-5)).contains(pos):
            self.setCursor(Qt.SizeHorCursor)
            self.value = 4

        #top_right catch
        elif QRect(QPoint(top_right.x(),top_right.y()), QPoint(top_right.x()-5,top_right.y()+5)).contains(pos):
            self.setCursor(Qt.SizeBDiagCursor)
            self.value = 5

        #botom_left catch
        elif QRect(QPoint(bottom_left.x(),bottom_left.y()), QPoint(bottom_left.x()+5,bottom_left.y()-5)).contains(pos):
            self.setCursor(Qt.SizeBDiagCursor)
            self.value = 6

        #top_left catch
        elif QRect(QPoint(top_left.x(),top_left.y()), QPoint(top_left.x()+5,top_left.y()+5)).contains(pos):
            self.setCursor(Qt.SizeFDiagCursor)
            self.value = 7

        #bottom_right catch
        elif QRect(QPoint(bottom_right.x(),bottom_right.y()), QPoint(bottom_right.x()-5,bottom_right.y()-5)).contains(pos):
            self.setCursor(Qt.SizeFDiagCursor)
            self.value = 8

        #default
        else:
            self.setCursor(Qt.ArrowCursor)       

    def resizing(self, ori, e, geo, value):    
        #top_resize
        if self.value == 1:
            last = self.mapToGlobal(e.pos())-ori
            first = geo.height()
            first -= last.y()
            Y = geo.y()
            Y += last.y()

            if first > self.minimumHeight():
                self.setGeometry(geo.x(), Y, geo.width(), first)                    
        
        #bottom_resize
        if self.value == 2:
            last = self.mapToGlobal(e.pos())-ori
            first = geo.height()
            first += last.y()
            self.resize(geo.width(), first)

        #right_resize
        if self.value == 3:
            last = self.mapToGlobal(e.pos())-ori
            first = geo.width()
            first += last.x()
            self.resize(first, geo.height()+1)

        #left_resize
        if self.value == 4:
            last = self.mapToGlobal(e.pos())-ori
            first = geo.width()
            first -= last.x()
            X = geo.x()
            X += last.x()

            if first > self.minimumWidth():
                self.setGeometry(X, geo.y(), first, geo.height()+1)

        #top_right_resize
        if self.value == 5:
            last = self.mapToGlobal(e.pos())-ori
            first_width = geo.width()
            first_height = geo.height()
            first_Y = geo.y()
            first_width += last.x()
            first_height -= last.y()
            first_Y += last.y()
                
            if first_height > self.minimumHeight():
                self.setGeometry(geo.x(), first_Y, first_width, first_height)

        #bottom_right_resize
        if self.value == 6:
            last = self.mapToGlobal(e.pos())-ori
            first_width = geo.width()
            first_height = geo.height()
            first_X = geo.x()
            first_width -= last.x()
            first_height += last.y()
            first_X += last.x()
                
            if first_width > self.minimumWidth():
                self.setGeometry(first_X, geo.y(), first_width, first_height)

        #top_left_resize
        if self.value == 7:
            last = self.mapToGlobal(e.pos())-ori
            first_width = geo.width()
            first_height = geo.height()
            first_X = geo.x()
            first_Y = geo.y()
            first_width -= last.x()
            first_height -= last.y()
            first_X += last.x()
            first_Y += last.y()
                
            if first_height > self.minimumHeight() and first_width > self.minimumWidth():
                self.setGeometry(first_X, first_Y, first_width, first_height)

        #bottom_right_resize
        if self.value == 8:
            last = self.mapToGlobal(e.pos())-ori
            first_width = geo.width()
            first_height = geo.height()
            first_width += last.x()
            first_height += last.y()                    
            
            self.setGeometry(geo.x(), geo.y(), first_width, first_height)           


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w4 = Widget4()
    w4.show()
    sys.exit(app.exec_())

Ответы (0 шт):