def __updateGeometry(self): # type: () -> None """ Update the shadow geometry to fit the widget's changed geometry. """ assert self.__widget is not None widget = self.__widget parent = self.__widgetParent radius = self.radius_ offset = self.__offset pos = widget.pos() if parent is not None and parent != widget.parentWidget(): pos = widget.parentWidget().mapTo(parent, pos) geom = QRect(pos, widget.size()) geom = geom.adjusted(-radius, -radius, radius, radius) geom = geom.translated(offset) if geom != self.geometry(): self.setGeometry(geom) # Set the widget mask (punch a hole through to the `widget` instance. rect = self.rect() mask = QRegion(rect) rect = rect.adjusted(radius, radius, -radius, -radius) rect = rect.translated(-offset) transparent = QRegion(rect) mask = mask.subtracted(transparent) self.setMask(mask)
def fitRect(rect, targetrect): size = rect.size().boundedTo(targetgeom.size()) newrect = QRect(rect.topLeft(), size) dx, dy = 0, 0 if newrect.left() < targetrect.left(): dx = targetrect.left() - newrect.left() if newrect.top() < targetrect.top(): dy = targetrect.top() - newrect.top() if newrect.right() > targetrect.right(): dx = targetrect.right() - newrect.right() if newrect.bottom() > targetrect.bottom(): dy = targetrect.bottom() - newrect.bottom() return newrect.translated(dx, dy)
def fitRect(rect, targetrect): size = rect.size().boundedTo(targetgeom.size()) newrect = QRect(rect.topLeft(), size) dx, dy = 0, 0 if newrect.left() < targetrect.left(): dx = targetrect.left() - newrect.left() if newrect.top() < targetrect.top(): dy = targetrect.top() - newrect.top() if newrect.right() > targetrect.right(): dx = targetrect.right() - newrect.right() if newrect.bottom() > targetrect.bottom(): dy = targetrect.bottom() - newrect.bottom() return newrect.translated(dx, dy)
def __layoutActions(self): # type: () -> None left, right = self.__actions contents = self.contentsRect() buttonSize = QSize(contents.height(), contents.height()) margins = self.textMargins() if left: geom = QRect(contents.topLeft(), buttonSize) left.button.setGeometry(geom) margins.setLeft(buttonSize.width()) if right: geom = QRect(contents.topRight(), buttonSize) right.button.setGeometry(geom.translated(-buttonSize.width(), 0)) margins.setLeft(buttonSize.width()) self.setTextMargins(margins)
def __layoutActions(self): left, right = self.__actions contents = self.contentsRect() buttonSize = QSize(contents.height(), contents.height()) margins = self.textMargins() if left: geom = QRect(contents.topLeft(), buttonSize) left.button.setGeometry(geom) margins.setLeft(buttonSize.width()) if right: geom = QRect(contents.topRight(), buttonSize) right.button.setGeometry(geom.translated(-buttonSize.width(), 0)) margins.setLeft(buttonSize.width()) self.setTextMargins(margins)