GridItem: Add custom line width based on pen option.#1709
GridItem: Add custom line width based on pen option.#1709nodedge wants to merge 1 commit intopyqtgraph:masterfrom nodedge:feature/grid-item-custom-width
Conversation
|
Hi @nodedge, Thanks for the PR. I'm in support of the feature, but in its current implementation it breaks default behavior. For example, running Same thing but on This can likely be worked around by checking if the pen has a default width, in which case set the pen width to Or alternatively a "better" implementation IMO would be to multiply the pen width by @NilsNemitz @ixjlyons do either of you have input. |
|
Probably the simplest way to handle this is to just extract the width in diff --git a/pyqtgraph/graphicsItems/GridItem.py b/pyqtgraph/graphicsItems/GridItem.py
index efb1afdb..ff9f8b6f 100644
--- a/pyqtgraph/graphicsItems/GridItem.py
+++ b/pyqtgraph/graphicsItems/GridItem.py
@@ -35,6 +35,7 @@ class GridItem(UIGraphicsItem):
self.opts['pen'] = fn.mkPen(*args, **kwargs)
self.picture = None
+ self._penWidth = self.opts['pen'].width()
self.update()
@@ -157,7 +158,6 @@ class GridItem(UIGraphicsItem):
linePen = self.opts['pen']
lineColor = self.opts['pen'].color()
- lineWidth = self.opts['pen'].width()
lineColor.setAlpha(c)
linePen.setColor(lineColor)
@@ -171,9 +171,9 @@ class GridItem(UIGraphicsItem):
for x in range(0, int(nl[ax])):
linePen.setCosmetic(False)
if ax == 0:
- linePen.setWidthF(lineWidth)
+ linePen.setWidthF(self._penWidth*self.pixelWidth())
else:
- linePen.setWidthF(lineWidth)
+ linePen.setWidthF(self._penWidth*self.pixelHeight())
p.setPen(linePen)
p1 = np.array([0.,0.])
p2 = np.array([0.,0.]) |
|
@nodedge , @j9ac9k |
|
Ahh yes, GridItem pens should most certainly be cosmetic. |
|
It's explicitly set to False - not sure why. |
|
Thank you for your answers. The example "GraphicsScene" is not broken anymore. |
|
I think I got to the bottom of this issue. The problem is this line I believe: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/graphicsItems/GridItem.py#L152 Since QPen's are mutable, we change the width of the pen's further down here: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/graphicsItems/GridItem.py#L166-L169 That change in width sort of throws out the initial setting we made. We can work around this by modifying linePen = fn.mkPen(self.opts['pen'])This returns a copy of the pen, where the width that was initially set to is preserved. @nodedge would you be ok with me pushing my changes to your branch? |


Hello,
Thank you for this awesome library.
We wish to contribute to it via this small PR.
The point is to customize the width of the GridItem lines.
Happy review!