0

我的 QGraphicsView 的背景是通过重载.drawBackground(...)和调用来设置的painter.drawImage(...)。我继续将前景对象添加到关联的 QGraphicsScene。这些大多是 QGraphicsRectItem 类型。我希望这些前景矩形中的每一个都将图像过滤器应用于它们所覆盖的背景的子图像。

  • 这可能吗?
  • 如果是这样,我在哪里可以找到一些示例代码来帮助我入门?谷歌搜索往往只找到用于事件过滤的代码。

提前致谢!

4

1 回答 1

0

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 before 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.

于 2012-05-22T20:57:02.643 回答