Filtrado de imágenes del fondo de QGraphicsView a través de QGraphicsItems en primer plano

The background of my QGraphicsView is set by overloading .drawBackground(...) y llamando painter.drawImage(...). I go on to add foreground objects to the associated QGraphicsScene. These are mostly of type QGraphicsRectItem. I'd like each of these foreground rectangles apply image filters to the subimage of the background that they cover.

  • ¿Es esto posible?
  • If so, where can I find a bit of example code to get me started? Googling tends to turn up nothing but code for event filtering.

Gracias de antemano!

preguntado el 22 de mayo de 12 a las 21:05

1 Respuestas

If your background is static, you could use this static image in the paintEvents of your (custom) item class. But as far as I know, you can't use Qt's item effects for this but need to implement the filters by your own in the paintEvents. Remember to crop the correct region out of the image for your filter.

There are some cases where you even don't need the background image. If you want to invert, for example, the background image covered by your item, just fill the whole region in the paintEvent of the item but set the composition mode of the painter antes the drawing appropriately. (See QPainter::CompositionMode for the available modes.)

If the background isn't static, it won't be possible without reusing the code of the drawBackground method or drawing the background on an image and then use this image to draw the actual background + for the effects in each item.

For a more specific answer, you should provide more information about the background and filters you want to have for the items.

contestado el 22 de mayo de 12 a las 21:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.