PDA

View Full Version : QGraphicsView crash on large size items in PyQt



Santa.fat
29th October 2015, 22:52
hi friends.

i have a QGraphicsScene with around 400 labels in it. when i increase initial size of labels program crashes.



scene = QtGui.QGraphicsScene()
scene.setBackgroundBrush(QtGui.QColor('white'))
graphics_widget = QtGui.QGraphicsWidget()
layout = QtGui.QGraphicsLinearLayout(QtCore.Qt.Vertical)
page_size = QtCore.QSize(995, 1242)
for number in xrange(400):
lbl = QtGui.QLabel()
lbl.setFixedSize(page_size)
lbl.setContentsMargins(0, 0, 0, 0)
lbl.setScaledContents(True)

widget = scene.addWidget(lbl)
layout.addItem(widget)

graphics_widget.setLayout(layout)
scene.addItem(graphics_widget)
self.gs_view.setScene(scene)
self.gs_view.show()

but when i decrease initial size of labels to ie QtCore.QSize(695, 942) it does not crash. sometimes when i scale QGraphicsView and my application memory usage is around 250mb i get and out of memory error and application exits automatically.

thank you.

Santa.fat
30th October 2015, 08:10
when i reduce number of pages (ie 30) program works fine with large size labels otherwise i should reduce size of labels or reduce number of pages.

for this project i should use PyQt 4.8.5 (Qt 4.7.4)

anda_skoa
30th October 2015, 10:12
Adding widgets to a graphicsscene should only be done if really needed, e.g. complex widgets or when needing platform styling of controls.
QLabel fits neither

Cheers,
_

Santa.fat
30th October 2015, 10:23
i want to write a docuement viewer and because of that i should initiate blank pages and when user scroll to a specific page render page's pixmap and show it to user.
even when i initiate pages with a small size and scale QGraphicsView some times i get out of memory error

anda_skoa
30th October 2015, 12:01
You might want to use a QListView then.
No point in creating visual delegates for things that cannot be seen.

Cheers,
_