Unsolved Qt crashes when having a dropshadow and opacity effect set to widgets
-
Hi,
I have a container widget with an opacity effect assigned to it, and a child widget that contains QToolButtons. This child has a dropshadow effect applied to it.
The opacity effect is used for fading the widget in / out. It works fine without the dropshadow effect, but with it, it crashes as soon as I hover over a toolbutton.
This is my widget code:
class MapWidget(QgsMapCanvas): def __init__(self, parent=None): super().__init__(parent) self.legend = LegendWidget(self) self._showLegend = True self.controls = MapControlsWidget() self.controlsContainer = QWidget(self) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.controls) self.controlsContainer.setLayout(layout) self.controlsEffect = QGraphicsOpacityEffect(self) self.controlsEffect.setOpacity(0) self.controlsContainer.setGraphicsEffect(self.controlsEffect) self.controlsOpacityAnimation: QPropertyAnimation = None self.dropShadow = QGraphicsDropShadowEffect(self) self.dropShadow.setOffset(1) self.dropShadow.setBlurRadius(4) self.controls.setGraphicsEffect(self.dropShadow) self.controls.targetButton.clicked.connect(self.onTargetButtonClicked) self.controls.zoomInButton.clicked.connect(self.onZoomInButtonClicked) self.controls.zoomOutButton.clicked.connect(self.onZoomOutButtonClicked) def onTargetButtonClicked(self) -> None: if self.layers(): self.zoomToSelected(self.layers()[0]) def onZoomInButtonClicked(self) -> None: self.zoomIn() def onZoomOutButtonClicked(self) -> None: self.zoomOut() @pyqtProperty(bool) def showLegend(self) -> bool: return self._showLegend @showLegend.setter def showLegend(self, value: bool) -> None: self._showLegend = value self.legend.setVisible(value) def resizeEvent(self, e): super().resizeEvent(e) self.controlsContainer.setGeometry( QRect(self.width() - self.controls.width() - 10, 10, self.controls.width(), self.controls.height()) ) def enterEvent(self, *args, **kwargs): super().enterEvent(*args, **kwargs) self.controlsOpacityAnimation = QPropertyAnimation(self.controlsEffect, b"opacity") self.controlsOpacityAnimation.setDuration(350) self.controlsOpacityAnimation.setStartValue(0) self.controlsOpacityAnimation.setEndValue(1) self.controlsOpacityAnimation.setEasingCurve(QEasingCurve.OutBack) self.controlsOpacityAnimation.start(QPropertyAnimation.DeleteWhenStopped) def leaveEvent(self, *args, **kwargs): super().leaveEvent(*args, **kwargs) self.controlsOpacityAnimation = QPropertyAnimation(self.controlsEffect, b"opacity") self.controlsOpacityAnimation.setDuration(350) self.controlsOpacityAnimation.setStartValue(1) self.controlsOpacityAnimation.setEndValue(0) self.controlsOpacityAnimation.setEasingCurve(QEasingCurve.InBack) self.controlsOpacityAnimation.start(QPropertyAnimation.DeleteWhenStopped)
Am I doing something wrong? I don't understand why it is crashing when hovering over a button.