naoyamakino
16th July 2009, 07:45
Hi there, I am looking for a way to change QLabel to QLineEdit when user clicks on it.
for example, MSN Messenger shows user name as label, and it changes to editable when user clicks on it; and it goes back to a label again when hit Enter.
is there any way to do that?
here is my code (this does not work, it does not change QLabel to QLineEdit when it detects mousePressEvent)
class class BuddyList(QtGui.QWidget):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self, parent)
#some initialization...#
#username
self.username = LineDisplay(self,self)
self.username.setGeometry(QtCore.QRect(120, 10, 121, 20))
class LineDisplay(QtGui.QLabel):
def __init__(self,buddyList,parent=None):
QtGui.QLabel.__init__(self, parent)
self.buddyList = buddyList
def mousePressEvent(self, event):
self.buddyList.username = None
self.buddyList.usernameInput = QtGui.QLineEdit(self)
self.buddyList.usernameInput.setGeometry(QtCore.QR ect(120, 10, 121, 20))
does anyone have an idea? or do you see anything wrong in my code?
I would very much appreciate for any kind of input.
thank you for your consideration.
best regards
Naoya Makino
for example, MSN Messenger shows user name as label, and it changes to editable when user clicks on it; and it goes back to a label again when hit Enter.
is there any way to do that?
here is my code (this does not work, it does not change QLabel to QLineEdit when it detects mousePressEvent)
class class BuddyList(QtGui.QWidget):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self, parent)
#some initialization...#
#username
self.username = LineDisplay(self,self)
self.username.setGeometry(QtCore.QRect(120, 10, 121, 20))
class LineDisplay(QtGui.QLabel):
def __init__(self,buddyList,parent=None):
QtGui.QLabel.__init__(self, parent)
self.buddyList = buddyList
def mousePressEvent(self, event):
self.buddyList.username = None
self.buddyList.usernameInput = QtGui.QLineEdit(self)
self.buddyList.usernameInput.setGeometry(QtCore.QR ect(120, 10, 121, 20))
does anyone have an idea? or do you see anything wrong in my code?
I would very much appreciate for any kind of input.
thank you for your consideration.
best regards
Naoya Makino