[PyQt] removeWidget

Hans-Peter Jansen hpj at urpla.net
Thu Aug 25 10:22:35 BST 2011


On Thursday 25 August 2011, 10:43:20 Vincent Vande Vyvre wrote:
>  Le 25/08/11 07:59, uahmed a écrit :
> Hi
>
>  I want to add widget in (f1) function and want to remove the widget
> from (f2) function . I tried the same thing in same function it do
> work but when i try to remove the widget from another it doesnt . Any
> help ?
>
>  Code :
>
>
>  import sys,os
>  from functools import partial
>  from PyQt4 import QtGui, QtCore
>  import Skype4Py
>  import time
>  import socket
>
>
>  class main():
>          def f1(self):
>                  print "f1"
>                  buttons['user'] = QtGui.QToolButton(widget)
>                  layout.addWidget(buttons['user'])
>                  widget.setLayout(layout)
>          def f2(self):
>                  print "f2"
>                  layout.removeWidget(buttons['user'])
>                  widget.setLayout(layout)
>
>
>  app = QtGui.QApplication(sys.argv)
>  widget = QtGui.QWidget()
>  layout = QtGui.QVBoxLayout()
>  buttons = {}
>  sk = main()
>  sk.f1()
>  sk.f2()
>  widget.show()
>  sys.exit(app.exec_())
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>  Remove is NOT delete.
>
>  Try that:
>
>  def f2(self):
>                  print "f2"
>                  buttons['user'].deleteLater()
>                  layout.removeWidget(buttons['user'])
>                  widget.setLayout(layout)

Consider using .show() and .hide()

Pete


More information about the PyQt mailing list