Setting widget "hitbox"
-
wrote on 30 Jun 2020, 18:31 last edited by
I want to create a widget in QGraphicScene and set its hitbox ( can't find a better word) to a non-rectangle region, like a polygon. I searched the doc, but did'nt find any obvious way to do that. Can you enlighten me ?
-
Hi,
Just to be sure we are on the same line, what would you use that hitbox for ?
-
wrote on 30 Jun 2020, 18:42 last edited by
For registering a clicked event for example, or a mouse hover
-
Then that's something you have to do yourself.
See the setAcceptHoverEvents, you'll have the related methods linked there that you may have to overload in order to do what you want.
-
wrote on 30 Jun 2020, 18:52 last edited by
Would it be better to simply "glue" some rectangulars widgets together, connecting directly the signals of the small widgets to the signals of the bigger one ?
-
Would it be better to simply "glue" some rectangulars widgets together, connecting directly the signals of the small widgets to the signals of the bigger one ?
@Pylvain
Hi
I get slightly confused when you say widget and QGraphicScene.
Do you have "real" widgets via QGraphicsProxyWidget
or do you mean the normal items like QGraphicsItem ? -
@mrjj Sorry, I mean Items, i'm not very familiar with the QGraphics* classes. That's just some pixmaps in want to display.
@Pylvain
Hi
thats super fine.
I just wanted to be sure you didnt use actual std widgets as that's also possible.If the goal is to have some images with some shapes
and you want to only be able to click inside the actual visual shape,
i think you can use
https://doc.qt.io/qt-5/qgraphicsitem.html#shape
for that. But you would have to create a QPainterPath that follows the visual image so to speak. -
wrote on 30 Jun 2020, 19:39 last edited by
@mrjj i saw that article, but i did'nt find anything useful. That can detect colisions, but nothing related with events. The more i think of it, the more i think it's best to use rectangular units glued together. It's simpler optimisationwise, and connecting signals to signals seems very elegant to me.
-
@mrjj i saw that article, but i did'nt find anything useful. That can detect colisions, but nothing related with events. The more i think of it, the more i think it's best to use rectangular units glued together. It's simpler optimisationwise, and connecting signals to signals seems very elegant to me.
@Pylvain
Its also used for hit testing.
That said if you can get the effect you want using rectangles, that should also work fine. -
wrote on 30 Jun 2020, 19:53 last edited by
I will use rectangular items glued together ! Thank you very much for your help !
7/11