Drop shadow not working
-
@poppypelt12 said in Drop shadow not working:
here is the code with the forums code tags
Better, but still not correct
@jsulm Could you please tell me what you think i did wrong? It is very important to me..! I think you are the only one who can help me with this...
-
@jsulm Could you please tell me what you think i did wrong? It is very important to me..! I think you are the only one who can help me with this...
@poppypelt12 Did you actually check whether self.ui.grid.findChildren(QPushButton) returned anything?
-
@poppypelt12 Did you actually check whether self.ui.grid.findChildren(QPushButton) returned anything?
@jsulm I dont know, but I tried doing it in another project on a regular single button, and it didn't work in there either, does it work for you?
-
@jsulm I dont know, but I tried doing it in another project on a regular single button, and it didn't work in there either, does it work for you?
@poppypelt12 Well, without ui_form I can't run your script.
-
@poppypelt12 Well, without ui_form I can't run your script.
@jsulm but can you add a drop shadow at all to any button? please if i cant figure this out i will cry :(
-
@jsulm but can you add a drop shadow at all to any button? please if i cant figure this out i will cry :(
@poppypelt12 You were asked to write MINIMAL script. You did not.
Here, I did it for you:import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QGraphicsDropShadowEffect class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) shadow = QGraphicsDropShadowEffect() shadow.setBlurRadius(10) # Adjust the blur radius as needed shadow.setXOffset(5) # Adjust the X offset as needed shadow.setYOffset(5) # Adjust the Y offset as needed self.button = QPushButton(self) self.button.setGraphicsEffect(shadow) if __name__ == '__main__': app = QApplication() mainWindow = MainWindow() mainWindow.show() app.exec()
And no, I don't see any drop shadow.
-
@jsulm but can you add a drop shadow at all to any button? please if i cant figure this out i will cry :(
@poppypelt12 This works:
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QGraphicsDropShadowEffect class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.shadow = QGraphicsDropShadowEffect() self.shadow.setBlurRadius(10) # Adjust the blur radius as needed self.shadow.setXOffset(5) # Adjust the X offset as needed self.shadow.setYOffset(5) # Adjust the Y offset as needed self.button = QPushButton(self) self.button.setGraphicsEffect(self.shadow) if __name__ == '__main__': app = QApplication() mainWindow = MainWindow() mainWindow.show() app.exec()
Do you know why? Hint: think about life time of "shadow" in the previous code.
-
@poppypelt12 You were asked to write MINIMAL script. You did not.
Here, I did it for you:import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QGraphicsDropShadowEffect class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) shadow = QGraphicsDropShadowEffect() shadow.setBlurRadius(10) # Adjust the blur radius as needed shadow.setXOffset(5) # Adjust the X offset as needed shadow.setYOffset(5) # Adjust the Y offset as needed self.button = QPushButton(self) self.button.setGraphicsEffect(shadow) if __name__ == '__main__': app = QApplication() mainWindow = MainWindow() mainWindow.show() app.exec()
And no, I don't see any drop shadow.
@jsulm Then pleaese how can i make a drop shadow? i searched everywhere on the internet but there is not much info on this and most of it is outdated, i really need your help
-
@poppypelt12 This works:
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QGraphicsDropShadowEffect class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.shadow = QGraphicsDropShadowEffect() self.shadow.setBlurRadius(10) # Adjust the blur radius as needed self.shadow.setXOffset(5) # Adjust the X offset as needed self.shadow.setYOffset(5) # Adjust the Y offset as needed self.button = QPushButton(self) self.button.setGraphicsEffect(self.shadow) if __name__ == '__main__': app = QApplication() mainWindow = MainWindow() mainWindow.show() app.exec()
Do you know why? Hint: think about life time of "shadow" in the previous code.
@jsulm Oh my god thank you so much!
-
@poppypelt12 This works:
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QGraphicsDropShadowEffect class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.shadow = QGraphicsDropShadowEffect() self.shadow.setBlurRadius(10) # Adjust the blur radius as needed self.shadow.setXOffset(5) # Adjust the X offset as needed self.shadow.setYOffset(5) # Adjust the Y offset as needed self.button = QPushButton(self) self.button.setGraphicsEffect(self.shadow) if __name__ == '__main__': app = QApplication() mainWindow = MainWindow() mainWindow.show() app.exec()
Do you know why? Hint: think about life time of "shadow" in the previous code.
@jsulm i am very thankful johann
-
@jsulm i am very thankful johann
@poppypelt12 It is common mistake to declare a local variable which is destroyed as soon as it goes out of scope. Just be careful when declaring variables and think about scope and life time of objects.