Re: [PyQt] Memory leak when using QAbstractTableModel
On Thursday 20 December 2007, Noam Raphael wrote: Hello, I created a simple program which uses QAbstractTableModel to display a table with 1000x1000 cells. It works, but if I enlarge the window and scroll a little bit the memory consumption of the program jumps to the skies (If I weren't careful, my system would have stuck.) Here's the program. I'm using PyQt 4.3-2ubuntu7 on Ubuntu 7.10. == #!/usr/bin/env python import sys from PyQt4 import QtCore, QtGui from PyQt4.QtCore import Qt class TableModel(QtCore.QAbstractTableModel): def rowCount(self, index): return 1000 def columnCount(self, index): return 1000 def data(self, index, role): return QtCore.QVariant(str((index.row(), index.column( def headerData(self, col, orientation, role): if orientation == Qt.Horizontal and role == Qt.DisplayRole: return QtCore.QVariant(str(col)) if orientation == Qt.Vertical and role == Qt.DisplayRole: return QtCore.QVariant(str(col)) return QtCore.QVariant() def main(): app = QtGui.QApplication(sys.argv) model = TableModel() tableView = QtGui.QTableView() tableView.setModel(model) tableView.show() sys.exit(app.exec_()) if __name__ == '__main__': main() == Is there some way I can solve this? Works fine for me with current versions. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Beginners - signal - slots - question
Hello, i finished my first Hello-World-PyQt-program sucessfully, but not my second. I googled for an example, but did not find any, so maybe you can give me a hint. There is a QLineEdit-element and a QLabel-element. When te user finished editing the QLineEdit, the text should be changed and then displayed in the QLabel. Which is the right QLineEdit-Signal? the action should start when return is pressed, but the signal returnPressed has no parameter QString and textChanged(QString) or textEdited(QString) react on every single input How do i place my own method, that changes the text? Thanks for any hint. beste gruesse jochen this is my code: BackwardsWriter.py: # -*- coding: utf-8 -*- import sys from PyQt4 import QtCore, QtGui class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(MainWindow) MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,471,330).size()).expandedTo(MainWindow.minimumSizeHint())) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(centralwidget) self.lineEdit = QtGui.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(40,40,401,51)) self.lineEdit.setObjectName(lineEdit) self.lb_Info = QtGui.QLabel(self.centralwidget) self.lb_Info.setGeometry(QtCore.QRect(40,120,401,51)) self.lb_Info.setAlignment(QtCore.Qt.AlignCenter) self.lb_Info.setObjectName(lb_Info) self.lb_ergebnis = QtGui.QLabel(self.centralwidget) self.lb_ergebnis.setGeometry(QtCore.QRect(30,200,401,51)) self.lb_ergebnis.setAlignment(QtCore.Qt.AlignCenter) self.lb_ergebnis.setObjectName(lb_ergebnis) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0,0,471,29)) self.menubar.setObjectName(menubar) MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(statusbar) MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) #QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(textChanged(QString)), self.lb_ergebnis, QtCore.SLOT(setText(QString))) #QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL(returnPressed()),self.blabla) # # ? # QtCore.QMetaObject.connectSlotsByName(MainWindow) def blabla(self): string_source = Hallo Welt string_drain = count = len(string_source) while count 0: string_drain = string_drain + string_source[count-1] count -= 1 print string_drain def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate(MainWindow, MainWindow, None, QtGui.QApplication.UnicodeUTF8)) self.lb_Info.setText(QtGui.QApplication.translate(MainWindow, Rückärts sieht das so aus:, None, QtGui.QApplication.UnicodeUTF8)) __ run.py : #!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtCore, QtGui from BackwardsWriter import Ui_MainWindow class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) if __name__ == __main__: app = QtGui.QApplication(sys.argv) myapp = MyForm() myapp.show() ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Beginners - signal - slots - question
Jochen Georges wrote: Hello, i finished my first Hello-World-PyQt-program sucessfully, but not my second. I googled for an example, but did not find any, so maybe you can give me a hint. There is a QLineEdit-element and a QLabel-element. When te user finished editing the QLineEdit, the text should be changed and then displayed in the QLabel. Which is the right QLineEdit-Signal? the action should start when return is pressed, but the signal returnPressed has no parameter QString and textChanged(QString) or textEdited(QString) react on every single input How do i place my own method, that changes the text? The self.lineEdit.text() method will return a QString. Just call it from the function tied to the returnPressed() signal. Doug. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Beginners - signal - slots - question
On Friday 21 December 2007, Jochen Georges wrote: Hello, i finished my first Hello-World-PyQt-program sucessfully, but not my second. I googled for an example, but did not find any, so maybe you can give me a hint. There is a QLineEdit-element and a QLabel-element. When te user finished editing the QLineEdit, the text should be changed and then displayed in the QLabel. Which is the right QLineEdit-Signal? the action should start when return is pressed, but the signal returnPressed has no parameter QString and textChanged(QString) or textEdited(QString) react on every single input How do i place my own method, that changes the text? Here's a hint that might get you going: Create a new slot for your own use :) In PyQt it’s just a python method, you can do anything in it. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Invalid protected on QItemDelegate ?
I am creating a custom QAbstractItemDelegate. It mostly acts as a proxy for standard QTreeWidget delegate. I cannot call the editorEvent() method on the original delegate because of this. return self.__real.editorEvent(event, model, option, index) RuntimeError: no access to protected functions or signals for objects not created from Python The documentation states the editorEvent is a public method, so I'm surprised to see this. Without calling the correct delegate the checkbox clicking action for QTreeWidgetItems is not processed. Or better than all this; is there an easier way to override the cell painting of a QTreeWidgetItem? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Invalid protected on QItemDelegate ?
On Friday 21 December 2007, Peter Shinners wrote: I am creating a custom QAbstractItemDelegate. It mostly acts as a proxy for standard QTreeWidget delegate. I cannot call the editorEvent() method on the original delegate because of this. return self.__real.editorEvent(event, model, option, index) RuntimeError: no access to protected functions or signals for objects not created from Python The documentation states the editorEvent is a public method, so I'm surprised to see this. Without calling the correct delegate the checkbox clicking action for QTreeWidgetItems is not processed. It's protected in QItemDelegate (which is what you mentioned in the subject). So what is the type of self.__real? It would be easier if you provied some code - preferably a small, complete example. Or better than all this; is there an easier way to override the cell painting of a QTreeWidgetItem? Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Beginners - signal - slots - question
On Friday 21 December 2007 12:26:02 Henrik Pauli wrote: On Friday 21 December 2007, Jochen Georges wrote: Hello, ..snip Which is the right QLineEdit-Signal? the action should start when return is pressed, but the signal returnPressed has no parameter QString and textChanged(QString) or textEdited(QString) react on every single input How do i place my own method, that changes the text? Here's a hint that might get you going: Create a new slot for your own use :) In PyQt it’s just a python method, you can do anything in it. OK, that works: (but it does not look like good style, does it?) QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL(returnPressed()),self.blabla) def blabla(self): #some code self.lb_ergebnis.setText(myString) #- QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL(returnPressed()), self.lb_ergebnis, QtCore.SLOT(setText(self.blabla))) def blabla(self): #some code return myString mmhhh ... how can i pass an argument to the slot-name? thanks for any hint beste gruesse jochen ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Beginners - signal - slots - question
On Friday 21 December 2007, Jochen Georges wrote: On Friday 21 December 2007 12:26:02 Henrik Pauli wrote: On Friday 21 December 2007, Jochen Georges wrote: Hello, ..snip Which is the right QLineEdit-Signal? the action should start when return is pressed, but the signal returnPressed has no parameter QString and textChanged(QString) or textEdited(QString) react on every single input How do i place my own method, that changes the text? Here's a hint that might get you going: Create a new slot for your own use :) In PyQt it’s just a python method, you can do anything in it. OK, that works: (but it does not look like good style, does it?) QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL(returnPressed()),self. blabla) def blabla(self): #some code self.lb_ergebnis.setText(myString) This is fine, really! #- QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL(returnPressed()), self.lb_ergebnis, QtCore.SLOT(setText(self.blabla))) def blabla(self): #some code return myString mmhhh ... how can i pass an argument to the slot-name? You don’t. Slots take as many arguments as they’re prepared for (in case of setText, one), and if the signal sends one, then it’ll work. Okay, it’s a bit more complicated than that, but that’s the core idea really. So if you wanted to do it fully signalslotted, you'd make a (py)signal which takes myString as an argument, connect it to setText, and emit it with blabla. (Unless I'm wrong... but that’s how I remember. Having to do Perl GTK stuff at work doesn’t help me keep my PyQt knowledge rustfree) QtCore.QObject.connect(self.lineEdit,QtCore.SIGNAL(returnPressed()), self.blabla) QtCore.QObject.connect(self, QtCore.PYSIGNAL(blabla2), self.lb_ergebnis, QtCore.SLOT(setText(QString))) ## no () after a pysignal's name def blabla(self): #some code self.emit( PYSIGNAL(blabla2), (myString,) ) ## N.B. the comma after the argument, that’s so it's a tuple. thanks for any hint beste gruesse jochen ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Large Table Example in PyQt4
On Thu, 20 Dec 2007 16:20:08 -0800 (PST), B Clowers wrote: I am fairly new to python and programming as a whole and would like to develop a small application capable of plotting simple 2D graphs and also display such data in a table. In my initial assessment of PyQt4 I have been able to load my data into a table but it is terribly slow. I am using a QAbstractTableModel example that I found on the web: http://iwiwdsmi.blogspot.com/2007/12/pyqt-43-qtableview-qabstracttable-model.html The model looks OK to me. I don't think it's doing anything special that would cause it to be inefficient. This has been useful but if I load a large numpy array (5 x 250,000) into this example it is insanely slow. It seems as though there was a bigtable.py example for PyQt3 but I cannot seem to port this to version 4. The paradigms for item views are different in Qt 3 and Qt 4. I don't think a solution for PyQt3 will help you much. The Qt website also discusses the use of large tables when programming C++ but this is out of my league. Does anyone have a simple solution to this problem or perhaps a quick example that I can insert a numpy array into? Again, I'm pretty new to python but am eager to learn. It would be interesting if you could run a profiler on your code so that we can see where the bottlenecks are. I recommend using qPyProfiler for this: http://www.digitalfox.org/projets/qPyProfiler/ It will be interesting to see where most of the CPU time is being spent. David ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt