BUG in label.width()?

20 views
Skip to first unread message

Zhiyi Liu

unread,
Feb 7, 2017, 5:06:39 PM2/7/17
to pyqtgraph
Hello,
When I draw couples of plots on the same canvas, the width of its legend window is wrong (it increases as the number of items increases). Please see the snapshot below. I try to print the width of each label (in LegendItem.py). It shows that label.width() is wrong except the last in the loop (looping self.items). Please confirm. The code is also attached.

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np

app
= pg.mkQApp()                
w
= pg.GraphicsLayoutWidget()
p
= w.addPlot()
legend
= p.addLegend()
legend
.setParentItem(p)

for i in range(20):
    p
.plot(x=range(0,10), y=np.array(range(0,10))*i, name='{0}'.format(i))

w
.show()
   
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
   
import sys
   
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
       
QtGui.QApplication.instance().exec_()


Cheers,
Zhiyi.




Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages