Drop shadow not working
-
In my UI i have a Main widger -> central widget -> grid-> 45 buttons and i want to apply drop shadow to all of them. I have added the libraries
(from PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QMessageBox, QGraphicsEffect, QPushButton, QGraphicsDropShadowEffect).I tried to apply it on a basic button BUT it didnt work there either. I made a try and exception to see if it doesent enter the drop shadow function. Here is the code in main:
for child in self.ui.grid.findChildren(QPushButton):
self.apply_drop_shadow(child)here is the function:
def apply_drop_shadow(self, widget):
shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10)
widget.setGraphicsEffect(shadow)any help is GREATLY appreciated! Thank you so much ...
-
In my UI i have a Main widger -> central widget -> grid-> 45 buttons and i want to apply drop shadow to all of them. I have added the libraries
(from PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QMessageBox, QGraphicsEffect, QPushButton, QGraphicsDropShadowEffect).I tried to apply it on a basic button BUT it didnt work there either. I made a try and exception to see if it doesent enter the drop shadow function. Here is the code in main:
for child in self.ui.grid.findChildren(QPushButton):
self.apply_drop_shadow(child)here is the function:
def apply_drop_shadow(self, widget):
shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10)
widget.setGraphicsEffect(shadow)any help is GREATLY appreciated! Thank you so much ...
Hi,
Please write a minimal script that creates a widget with a button in it and applies the drop shadow on it.
-
Hi,
Please write a minimal script that creates a widget with a button in it and applies the drop shadow on it.
@SGaist here is what i wrote:
import sysfrom PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QMessageBox, QPushButton, QGraphicsDropShadowEffect, QTableWidget, QTableWidgetItem
from PySide6.QtGui import QIcon, QPixmap
from PySide6.QtCore import Qt, QSize, QPropertyAnimation, QEasingCurve, QPointfrom ui_form import Ui_MainWindow
import re
class MainWindow(QMainWindow):
def init(self, parent=None):
super().init(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
for child in self.ui.grid.findChildren(QPushButton):
self.apply_drop_shadow(child)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 # Apply the drop shadow effect to the button self.ui.legendButton.setGraphicsEffect(shadow) self.ui.legend.setMinimumWidth(286) self.ui.legendButton.setVisible(True) #self.apply_drop_shadow(self.ui.legendButton) self.ui.button_area.setGeometry(70, 0, 1800, 1080) self.setWindowTitle("Vital Alert") self.setWindowIcon(QIcon("logo.png")) self.populate_buttons() self.set_icons() self.showFullScreen() def apply_drop_shadow(self, widget): shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10) widget.setGraphicsEffect(shadow)
if name == "main":
app = QApplication(sys.argv)
widget = MainWindow()
widget.show()
sys.exit(app.exec()) -
@SGaist here is what i wrote:
import sysfrom PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QMessageBox, QPushButton, QGraphicsDropShadowEffect, QTableWidget, QTableWidgetItem
from PySide6.QtGui import QIcon, QPixmap
from PySide6.QtCore import Qt, QSize, QPropertyAnimation, QEasingCurve, QPointfrom ui_form import Ui_MainWindow
import re
class MainWindow(QMainWindow):
def init(self, parent=None):
super().init(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
for child in self.ui.grid.findChildren(QPushButton):
self.apply_drop_shadow(child)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 # Apply the drop shadow effect to the button self.ui.legendButton.setGraphicsEffect(shadow) self.ui.legend.setMinimumWidth(286) self.ui.legendButton.setVisible(True) #self.apply_drop_shadow(self.ui.legendButton) self.ui.button_area.setGeometry(70, 0, 1800, 1080) self.setWindowTitle("Vital Alert") self.setWindowIcon(QIcon("logo.png")) self.populate_buttons() self.set_icons() self.showFullScreen() def apply_drop_shadow(self, widget): shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10) widget.setGraphicsEffect(shadow)
if name == "main":
app = QApplication(sys.argv)
widget = MainWindow()
widget.show()
sys.exit(app.exec())@poppypelt12 Please use code tags properly, especially when posting Python code where indentation is part of the syntax!
-
@poppypelt12 Please use code tags properly, especially when posting Python code where indentation is part of the syntax!
@jsulm Sorry, I am a beginner haha :) i copied the code and pasted it but my program is more complex but this is the relevant part. Did i do something wrong with how i wrote the drop shadow or did i leave out a library? :(
-
@jsulm Sorry, I am a beginner haha :) i copied the code and pasted it but my program is more complex but this is the relevant part. Did i do something wrong with how i wrote the drop shadow or did i leave out a library? :(
@poppypelt12
We are just asking you: when you paste code blocks, please enclose them in the forum's Code tags (the</>
button). This will post all the code literally, including spacing, which is so vital in Python. -
@poppypelt12
We are just asking you: when you paste code blocks, please enclose them in the forum's Code tags (the</>
button). This will post all the code literally, including spacing, which is so vital in Python.@JonB Okay, here is the code with the forums code tags ^^
<class MainWindow(QMainWindow):
def init(self, parent=None):
super().init(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)self.room_instance = Room(None, None, None) self.data=self.room_instance.read_data_from_file("rooms.json") self.ui.settings.clicked.connect(self.showSettings) self.ui.panels.clicked.connect(self.showPanels) self.ui.legendButton.clicked.connect(self.legend_change_size) for child in self.ui.grid.findChildren(QPushButton): self.apply_drop_shadow(child) 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 # Apply the drop shadow effect to the button self.ui.legendButton.setGraphicsEffect(shadow) self.ui.legend.setMinimumWidth(286) self.ui.legendButton.setVisible(True) #self.apply_drop_shadow(self.ui.legendButton) self.ui.button_area.setGeometry(70, 0, 1800, 1080) self.setWindowTitle("Vital Alert") self.setWindowIcon(QIcon("logo.png")) self.populate_buttons() self.set_icons() self.showFullScreen() def apply_drop_shadow(self, widget): shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10) widget.setGraphicsEffect(shadow)
/>
-
@JonB Okay, here is the code with the forums code tags ^^
<class MainWindow(QMainWindow):
def init(self, parent=None):
super().init(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)self.room_instance = Room(None, None, None) self.data=self.room_instance.read_data_from_file("rooms.json") self.ui.settings.clicked.connect(self.showSettings) self.ui.panels.clicked.connect(self.showPanels) self.ui.legendButton.clicked.connect(self.legend_change_size) for child in self.ui.grid.findChildren(QPushButton): self.apply_drop_shadow(child) 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 # Apply the drop shadow effect to the button self.ui.legendButton.setGraphicsEffect(shadow) self.ui.legend.setMinimumWidth(286) self.ui.legendButton.setVisible(True) #self.apply_drop_shadow(self.ui.legendButton) self.ui.button_area.setGeometry(70, 0, 1800, 1080) self.setWindowTitle("Vital Alert") self.setWindowIcon(QIcon("logo.png")) self.populate_buttons() self.set_icons() self.showFullScreen() def apply_drop_shadow(self, widget): shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10) widget.setGraphicsEffect(shadow)
/>
@poppypelt12 said in Drop shadow not working:
here is the code with the forums code tags
Better, but still not correct
-
@JonB Okay, here is the code with the forums code tags ^^
<class MainWindow(QMainWindow):
def init(self, parent=None):
super().init(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)self.room_instance = Room(None, None, None) self.data=self.room_instance.read_data_from_file("rooms.json") self.ui.settings.clicked.connect(self.showSettings) self.ui.panels.clicked.connect(self.showPanels) self.ui.legendButton.clicked.connect(self.legend_change_size) for child in self.ui.grid.findChildren(QPushButton): self.apply_drop_shadow(child) 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 # Apply the drop shadow effect to the button self.ui.legendButton.setGraphicsEffect(shadow) self.ui.legend.setMinimumWidth(286) self.ui.legendButton.setVisible(True) #self.apply_drop_shadow(self.ui.legendButton) self.ui.button_area.setGeometry(70, 0, 1800, 1080) self.setWindowTitle("Vital Alert") self.setWindowIcon(QIcon("logo.png")) self.populate_buttons() self.set_icons() self.showFullScreen() def apply_drop_shadow(self, widget): shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10) widget.setGraphicsEffect(shadow)
/>
-
@J-Hilk
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QMessageBox, QPushButton, QGraphicsDropShadowEffect, QTableWidget, QTableWidgetItem from PySide6.QtGui import QIcon, QPixmap from PySide6.QtCore import Qt, QSize, QPropertyAnimation, QEasingCurve, QPoint from ui_form import Ui_MainWindow from add_room import AddRoomDialog from room import Room from settings import Settings from panels import Panels import re class MainWindow(QMainWindow): def __init__(self, parent=None): super().__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.legendButton.clicked.connect(self.legend_change_size) for child in self.ui.grid.findChildren(QPushButton): self.apply_drop_shadow(child) 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 # Apply the drop shadow effect to the button self.ui.legendButton.setGraphicsEffect(shadow) self.ui.legend.setMinimumWidth(286) self.ui.legendButton.setVisible(True) #self.apply_drop_shadow(self.ui.legendButton) self.ui.button_area.setGeometry(70, 0, 1800, 1080) self.setWindowTitle("Vital Alert") self.setWindowIcon(QIcon("logo.png")) self.populate_buttons() self.set_icons() self.showFullScreen() def apply_drop_shadow(self, widget): shadow = QGraphicsDropShadowEffect(blurRadius=5, xOffset=10, yOffset=10) widget.setGraphicsEffect(shadow)
thank you for the inpot
-
@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