1

I'm doing a PyQt5 GUI application. I'd like to have a blur/grey out effect animation appearing over a MainWindow while opening/editing a DialogWindow. In resume, I'd like to achieve this effect.

I have already tried to setEnable(True) and make the dialog modal while opening it. But both windows get stuck and I don't have the wanted blur/grey out effect.

def open_importing_dialog(self):
    self.importing = ImportingData(self)
    self.setEnabled(False)
    self.repaint()
    self.importing.setEnabled(True)
    self.importing.setWindowFlag(Qt.WindowStaysOnTopHint)
    self.importing.finished.connect(lambda: self.setEnabled(True))
    self.importing.show()

And tried to make a overlay widget with QGraphicsBlurEffect, but nothing happened.

def open_importing_dialog(self):
    blur = QtWidgets.QGraphicsBlurEffect()
    blur.setBlurRadius(10)
    blur_overlay = QWidget(self)
    blur_overlay.setGraphicsEffect(blur)
    blur_overlay.setGeometry(self.geometry())
    self.importing = ImportingData(self)
    self.importing.exec_()

Could you help me in this issue? Or even give me some tips to achieve it? Appreciate!

(Obs.: I have a link from YouTube showing how this effect works, but I don't know if I can drop external links here. If it's okay, I could drop it in a comment for you to have a better idea how is this effect I want)

Igor
  • 21
  • 3
  • FYI that is a WPF program in that video. – Alexander Aug 25 '23 at 03:25
  • Graphics effects are applied on the widget (and its children), not what's "behind" them. Remove that `blur_overlay` widget and just apply the effect on the top level window. If you want it to animate, use QPropertyAnimation. – musicamante Aug 25 '23 at 10:50
  • @Alexander I'm aware about it. I just wanted to reproduce that effect in PyQt5 – Igor Aug 25 '23 at 13:19
  • @musicamante I got it. I've created a rect widget filled with some transparency and made it a child of my centralWidget. I hide it after creating and show when I want. It works beautifully. I got all the code from these answers [link](https://stackoverflow.com/questions/19362455/dark-transparent-layer-over-a-qmainwindow-in-qt/19367454#19367454) [link](https://stackoverflow.com/questions/19383427/blur-effect-over-a-qwidget-in-qt/19386886#19386886) – Igor Aug 25 '23 at 13:28
  • Now I want to block my MainWindow from user editing, but keep my DialogWindow editable :( – Igor Aug 25 '23 at 13:30
  • @Igor I don't see the point of creating a further widget, as already said you just need to set the effect on the window. If you're doing it to be able to remove the effect, that's not correct: either call the effect's `setEnabled()` or just call `setGraphicsEffect(None)`. If you use the dialog's `exec()` or `open()` functions, that will automatically make the dialog modal, preventing interactions with other windows until it's closed. – musicamante Aug 25 '23 at 13:35
  • @musicamante the point is that applying the affect on the window didn't work for me, why? I dunno hahaha. The exec( ) function was not working as well (nothing works for me as you see haha, I dunno if it's my app or because I'm a newbie :( ), but I just find [this answer](https://stackoverflow.com/questions/22410663/block-qmainwindow-while-child-widget-is-alive-pyqt) and it works. – Igor Aug 25 '23 at 14:06
  • Sorry but we can't help you if we don't know what doesn't "work" for you. You must explain **what** doesn't work: the effect wasn't applied? it's only partially applied? the dialog doesn't show? the other window is still able to get user events? Please provide more details, as you may be doing the wrong thing for the wrong reasons. Also, your link has *six* answers, which one are you referring to? Note that *accepted* one (using `exec()`) is also the normally accepted approach for basic situations, but if we don't have a more comprehensive context we cannot know that. Please provide a [mre]. – musicamante Aug 25 '23 at 14:21

0 Answers0