python 2.7 - puqt4 clearing the line edit field -


i am trying create tqo line edit , when click on line edit box should able clear current text.

i tried below code no success ,

can 1 point out whats wrong here ?

options = ['enter ip address',                'number of iteration']      def __init__(self, parent=none):         qtgui.qwidget.__init__(self, 'details', parent=parent)         self.options = {}         option in optionbox.options:             self.options[option] = (qtgui.qlineedit(option))             self.connect(self.options[option],  qtcore.signal("clicked()"), self.clicked)         self._gridoptions()      def clicked(self):         qlineedit.clear() 

you need use event filter on qlineedit catch click event in (https://qt-project.org/doc/qt-5.1/qtcore/qobject.html#eventfilter). here example on how code should like:

def __init__(self, parent=none):   qtgui.qwidget.__init__(self, 'details', parent=parent)   self.options = {}   option in optionbox.options:     self.options[option] = qtgui.qlineedit(option)     self.options[option].installeventfilter(self)   self._gridoptions()  def eventfilter(self, object, event):   if (object in self.options.values()) , (event.type() == qtcore.qevent.mousebuttonpress):     object.clear()     return false # lets event continue edit   return false 

edit: understand, want default text appear in qlineedit describe role. opportunity use placeholdertext. here code modified use (there no more need of eventfilter method):

def __init__(self, parent=none):   qtgui.qwidget.__init__(self, 'details', parent=parent)   self.options = {}   option in optionbox.options:     self.options[option] = qtgui.qlineedit()     self.options[option].setplaceholdertext(option)   self._gridoptions() 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -