How to disable setGraphicsEffect inheritance to children in Qt?
For example, imagine my project has this hierarchy:

When I apply a shadow with setGraphicsEffect to the frame the line edit will inherit that shadow effect, and I don't want that. This is what I'am getting:

As you can see, there's a shadow around the letters of the line edit. Any idea how to fix this?
One more thing.. visibly in the image above the MainWindow has some flags like Qt::FramelessWindowHint and Qt::WA_TranslucentBackground so the frame is supposed to be the "window", and the frame automatically resizes when I resize the MainWindow so I can't change that hierarchy.
As requested by Timusan here is the code of the shadow: Qt: shadow around window
To apply it to the frame:
CustomShadowEffect *shadow = new CustomShadowEffect();
shadow->setColor(c);
shadow->setDistance(scale);
shadow->setBlurRadius(blur_radius);
ui->frame->setGraphicsEffect(shadow);
UPDATE
layout()->addWidget(ui->lineEdit);
Documentation of QGraphicsItem::setGraphicsEffect states that
Note: This function will apply the effect on itself and all its children.
thus the behaivor you are expecting is correct.
What I'd suggest is overriding the graphics item on the QLineEdit explicitly by calling either setGraphicsEffect(NULL) or by getting the default text effect of the line edit and then setting it back after your custom effect on the frame has been applied. I'm not sure if the line edit has a default effect or not, thus not sure if the NULL approach will do.
UPDATE
As stated by the OP the proposed way of overriding the existing effect by calling QGraphicsItem::setGraphicsEffect with null does not work. So given that I see 2 further possibilies:
QLineEdit a child of the frame (not sure if that is possible, you mentioned that frame cannot be unbound from the window but nothing about frame to line edit relationship constraints).CustomShadowEffect you could tweak the draw() method to ignore calls with QPainter that belongs to the line edit. What you could do is keep a list of ignored QPaintDevice instances in the effect - QWidget inherits QPaintDevice and you can query the QPaintDevice pointer from the QPainter via QPainter::device, so you can simply add the widgets to your internal list and then in the draw method compare the QPaintDevice of the incoming QPainter to the ignored ones.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With