Hi,

I've written a very simple app that uses Qt's model/view
with PySide but unfortunately it leaks somewhere.

Model is QStandardItem with 2 rows and 2 columns.
First column is for 'title' it is displayed in QTreeView,
second column is 'content' it's not displayed in treeview.
Current selected row's content is displayed textEdit.
Whenever textEdit changes it updates the model.

If you do a lot of editing in textEdit you'll see a memory
leak. It can be quickly reproduced with copy/pasting this
application's code a number of times and then deleting it.

Actual source code:


import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Window(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        self.model = QStandardItemModel(2,2)
        self.model.setItem(0, 0, QStandardItem('title1'))
        self.model.setItem(0, 1, QStandardItem(''))
        self.model.setItem(1, 0, QStandardItem('title2'))
        self.model.setItem(1, 1, QStandardItem(''))
        self.textEdit = QTextEdit(self)
        self.textEdit.textChanged.connect(self._text_changed)
        self.treeView = QTreeView(self)
        self.treeView.setModel(self.model)
        self.treeView.hideColumn(1)
        self.selectionModel = self.treeView.selectionModel()
        self.selectionModel.currentRowChanged.connect(self._current_row_changed)
        self.selectionModel.setCurrentIndex(self.model.index(0,0),
QItemSelectionModel.Select)
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.addWidget(self.treeView)
        self.verticalLayout.addWidget(self.textEdit)

    def _current_row_changed(self, current, previous):
        currenttextitem = self.model.item(current.row(), 1)
        currenttext = currenttextitem.text()
        self.textEdit.setPlainText(currenttext)

    def _text_changed(self):
        currentrow = self.selectionModel.currentIndex().row()
        item = self.model.item(currentrow, 1)
        item.setText(self.textEdit.toPlainText())

if __name__ == '__main__':
    app = QApplication([])
    w = Window()
    w.show()
    sys.exit(app.exec_())


p.s.
- Mac OS 10.6.8
- PySide 1.0.5
- Python 2.7

---
Den Sh
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to