Make QGraphicsItem cover items under it
mbise1993 last edited by mbise1993
I'm working with the graphics view framework on a project and I've run into a problem where I'm adding a
QGraphicsRectItemto a scene and setting its brush, but the item under it is still visible. I've tried setting the Z value, but the items aren't exactly siblings so it has no effect. The hierarchy is:
Measure - Line - Beat - Note
I'm trying to make the note cover the line that it is on. As you can see in the screenshot, the line is still visible over the red background of the note. Anyone have any ideas?
@mbise1993 Did you try to set opacity https://doc.qt.io/qt-5/qgraphicsitem.html#setOpacity ?
@jsulm I just tried setting the opacity on the note item to 1.0, but it didn't help.
@mbise1993 Try to set ItemIgnoresParentOpacity via https://doc.qt.io/qt-5/qgraphicsitem.html#setFlags
@jsulm Unfortunately, that wasn't it either.
I found the problem. I was drawing the beats before the lines, so the lines took precedent over the beats since they are siblings. The solution was to either draw the beats last or set the Z value on the beat, not the note.