[Interest] Custom QQuickItem with Mouse area

Jérôme Godbout jerome at bodycad.com
Fri Feb 6 16:38:11 CET 2015


Hi,
just a follow up. I dig a bit around this, look like the QQuickItem new
grab functions (5.4+) could be used to create an Image element:

MyCustomItem
{
  id: c
  // Not sure how to do this without flooding it
  onChanged: c.grabToImage(function (result) { i.source = result.url; })
}

Image
{
  id: i
  // get it out the display way, cannot make it insivible would not load I
guess
  x: -20000
  y: -20000
}

MouseArea
{
  anchors.fill: c
  onClicked:
  {
     if(myCustomFunctionThatExtractPixelColorValue(i, mouse.x, mouse.y).a
<= 0)
     {
         // not on draw area
         return;
     }
     // Do normal wanted behavior if clicked on it
     ...
     mouse.accepted = true;
  }
}

I cannot test this yet, we are stuck with Qt 5.3.0 (because of mouse scroll
wheel behavior into 5.3.1+)  and the grabToImage appear into 5.4.

At first sight I suspect this would be extremely slow to do it this way.

Maybe there's a way to render the Item into a texture and expose that
pixmap to the Qml application to perform the proper operation on mouse
area.

Maybe ShaderEffectSource could be used somehow but I cannot figure out how
I could make it work to acheive that.

We already do the mouse area alpha trick with custom Image to display
button like elements and it work relatively well (not a speed demon, but
work at least). Imagine a U shape image where the mouse area only activate
when over the draw U part and not into the void in between. This become
particulary usefull when using multiple image into the same rectangle area
to perform different operation.

If somebody have a better idea to do those thing.

Thanks
Jerome

On Thu, Feb 5, 2015 at 6:43 PM, Jérôme Godbout <jerome at bodycad.com> wrote:

> Hi, I'm trying to create a custom QItem by enabling flag ItemHasContent to
> true and defining the updatePaintNode() function. It work well and it's
> fast even for large number of item, 2d points to create a shape. But the
> mouse area for those draw item are the whole bounding rectangle containing
> the item. Is there a way to create a mask image of the rendered item to
> filter mouse event based on the Item draw pixel? or is there a better way
> to only trigger mouse event only on Item draw area (alpha <1)?
>
> Thanks, Jerome
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150206/afdc40e9/attachment.html>


More information about the Interest mailing list