[Qt-interest] Events on Transparent Window
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Thu Feb 10 10:21:39 CET 2011
On 2011-02-09 Sean Sean Hayes wrote:
> ...
> Setting full transparency causes Windows to send the event directly to
> the window underneath, defeating the purpose. Any ideas on how to
> force the transparent window to receve events? I have tried this with QWidget::setWindowOpacity(0).
I am completely shooting into the blue here, but in my case setting QGraphicsItem#setShapeMode() to the value 'QGraphicsPixmapItem::BoundingRectShape' helped.
My case is that I have QGraphicsPixmapItems with an alpha gradient. I observed that - as in your case apparently - the item by default did not receive any mouse events when clicking into the gradient with full transparency (alpha = 0). And this is usually what is desired, because the most common use case would be to have some graphic shape which should only be clickable where visible, so setting the alpha value to 0 serves as a "mask". But when setting the "shape mode" to the mentioned BoundingRectShape value makes sure that the item receives mouse clicks inside its entire bounding rect (the rectangle of the pixmap, in this case).
So far for mouse clicks, I am not sure if this also affects touch events. It's worth a shot...
But looking at http://doc.qt.nokia.com/4.7/qgraphicsitem.html#GraphicsItemFlag-enum there are a few other flags which might be helpful (in case you did not try them out already):
- QGraphicsItem::ItemClipsToShape: "The item cannot draw or receive mouse, tablet, drag and drop or hover events outside its shape."
At least it mentions events. The documentation is a bit sketchy here, since it sais "it is disabled by default", but "enforced by QGraphicsView::drawItems() or QGraphicsScene::drawItems()". So what now? ;)
- QGraphicsItem::ItemHasNoContents: "The item does not paint anything (i.e., calling paint() on the item has no effect)."
The most promising one I'd say: so maybe instead of setting the item to "fully transparent" you could set this flag. Hopefully the item would not be painted, but still receive (touch) events - exactly what you would need.
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list