Controlling Selection in QGraphicsView/Scene/Items
-
I have looked at all of the documentation but before I plow into the QT source code, I have three questions about selections in QGraphics views and scenes:
-
Is there an easy way to control the tolerance of hit testing. I am selecting thin paths, but can't really use bounding boxes... I need to have a couple of pixel tolerance on mouse location when clicked.
-
Who controls the way selected items are rendered? Default is a dashed outline of the bounding box, but I would like to change this. Is this controlled by each item, or by the scene or view?
-
Is there anyway to control how keys impact selection? Default (on Mac) is command key allows multiple selection... but not with multiple drags.
Thanks for any insights from experience that might save some hours of reading the source code.
Glenn
-
-
[quote author="gkroeger" date="1297035094"]1. Is there an easy way to control the tolerance of hit testing. I am selecting thin paths, but can't really use bounding boxes... I need to have a couple of pixel tolerance on mouse location when clicked.[/quote]
Try overriding QGraphicsScene::mousePressEvent() and use boundingRect().adjusted(x1, y1, x2, y2).
[quote author="gkroeger" date="1297035094"]2. Who controls the way selected items are rendered? Default is a dashed outline of the bounding box, but I would like to change this. Is this controlled by each item, or by the scene or view?[/quote]
It's the item itself and it uses some settings from the QStyleOptionGraphicsItem * parameter passed to the paint() function. However, it probably just states that the item is selected and not so much what kind of line style to use to draw the selection (didn't verify this).
[quote author="gkroeger" date="1297035094"]3. Is there anyway to control how keys impact selection? Default (on Mac) is command key allows multiple selection... but not with multiple drags.[/quote]There may be a smarter way, but you can always go in with the blunt axe and override keyPressEvent() and mousePressEvent(). Look into the QGraphicsScene documentation for which events you can override in it.