[PyQt] Updating Qlabel in widget
Hi I want to update the Qlabel after the widget is made , Problem is that updating is base on counter so i call that function after 4 seconds , but when it by pass the if statment it go through all the commands give me no errors but it does not update the widet although if i dont putt if statment all lines are executed and Qlabel update too . Can you please tell me where i am wrong Here is code import sys,os from functools import partial from PyQt4 import QtGui, QtCore import time class main(): def f2(self): print f2 global count count +=1 if ( count == 2): msg_label[user] = QtGui.QLabel(update,widget) msg_label[user].setGeometry(10, 10, 100, 100) print count QtCore.QTimer.singleShot(4000, self.f2) app = QtGui.QApplication(sys.argv) widget = QtGui.QWidget() layout = QtGui.QVBoxLayout() buttons = {} count = 0 msg_label = {} sk = main() sk.f2() widget.show() sys.exit(app.exec_()) ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Updating Qlabel in widget
On Thursday 25 August 2011, 12:02:52 uahmed wrote: Hi I want to update the Qlabel after the widget is made , Problem is that updating is base on counter so i call that function after 4 seconds , but when it by pass the if statment it go through all the commands give me no errors but it does not update the widet although if i dont putt if statment all lines are executed and Qlabel update too . Can you please tell me where i am wrong Here is code import sys,os from functools import partial from PyQt4 import QtGui, QtCore import time class main(): def f2(self): print f2 global count count +=1 if ( count == 2): msg_label[user] = QtGui.QLabel(update,widget) msg_label[user].setGeometry(10, 10, 100, 100) print count QtCore.QTimer.singleShot(4000, self.f2) app = QtGui.QApplication(sys.argv) widget = QtGui.QWidget() layout = QtGui.QVBoxLayout() buttons = {} count = 0 msg_label = {} sk = main() sk.f2() widget.show() sys.exit(app.exec_()) Don't recreate the widget over and over again. Create it once, and just change the label with setText(). Pete ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Updating Qlabel in widget
hi Thanks for the reply , QLabel will be created once only when count is equal to 2 . Firstly i was thinking same that i make Qlabel first and then recall them and change only text but if i do that then i have to create nearly 40-60 Qlabel to cover all the loop holes so i need to create it on run time to avoid making lots of Qlabels On Thu, Aug 25, 2011 at 3:26 PM, Hans-Peter Jansen h...@urpla.net wrote: On Thursday 25 August 2011, 12:02:52 uahmed wrote: Hi I want to update the Qlabel after the widget is made , Problem is that updating is base on counter so i call that function after 4 seconds , but when it by pass the if statment it go through all the commands give me no errors but it does not update the widet although if i dont putt if statment all lines are executed and Qlabel update too . Can you please tell me where i am wrong Here is code import sys,os from functools import partial from PyQt4 import QtGui, QtCore import time class main(): def f2(self): print f2 global count count +=1 if ( count == 2): msg_label[user] = QtGui.QLabel(update,widget) msg_label[user].setGeometry(10, 10, 100, 100) print count QtCore.QTimer.singleShot(4000, self.f2) app = QtGui.QApplication(sys.argv) widget = QtGui.QWidget() layout = QtGui.QVBoxLayout() buttons = {} count = 0 msg_label = {} sk = main() sk.f2() widget.show() sys.exit(app.exec_()) Don't recreate the widget over and over again. Create it once, and just change the label with setText(). Pete ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt