lazy create the rectangle selection item#2168
Conversation
| self.sigStateChanged.emit(self) | ||
|
|
||
| def _add_rectangle_selection(self): | ||
| if self.reScaleBox is None and self.state['mouseMode'] == ViewBox.RectMode: |
There was a problem hiding this comment.
self.reScaleBox should be a typo for self.rbScaleBox?
As it is, a new QGraphicsRectItem is instantiated each time mouseMode changes to RectMode
There was a problem hiding this comment.
Yes, that was a typo 🤦♂️
|
Hi @danielhrisca thanks for the PR. Only comment I have is should that hidden method remove the rectangular selection box if setMouseMode is set to PanMode, after initially being in RectMode. This PR I don't think will attempt to remove the selection rectangle in that condition. |
My idea was that the CPU cycles were already used to create it, so removing it would only save some memory. Do you think it is better to remove it if the mouse mode is set to PanMode? |
We're talking few cycles and little memory here, so I don't think it makes a noticeable difference either way. I remember for your use-case you overlap many viewboxes, so i'm inclined to follow your lead here... removing the scale box would only occur on changing of the mouse mode, which I suspect is a time we have some cycles to spare. Either way, not going to hold up this PR on this, was just throwing out the idea is all 👍🏻 |
|
Blerg, should have merged this long ago, sorry for the wait @danielhrisca Thanks for the PR. |
|
Absolutely no problem 👍 |
|
FYI PyQt6 6.3.1 just introduced a new Also if you want to get ahold of us on not the issue tracker, we now have a discord channel on the main python discord server here: https://discord.com/channels/267624335836053506/898139460821192724 |
|
Thanks for the tip. In my code I use In my work project we also use |
|
Now that #2324 is merged, if you set |
In the current implementation for each ViewBox there will be a rectangle selection item. If the mouse mode is set to PanMode then this rectangle is unused.
With this PR the rectangle is only created if it is really needed.