Results 1 to 3 of 3

Thread: line edit data input

  1. #1
    Join Date
    Apr 2015
    Posts
    3
    Qt products
    Platforms
    Windows

    Default line edit data input

    Hi, i would love a little direction here please as i have been searching but not finding a solution to my issue.
    What i would love is to take the data i enter into the line edit field of my gui and send that data to a string in my list. In the case below it is the value at ls[0] that i want to change to the value i enter in the gui line edit field. (not using line edit_2 at the moment) Am i going about it the wrong way?

    Qt Code:
    1. from PyQt4 import QtCore, QtGui
    2. import sys
    3.  
    4. ls = ["a", "b"]
    5.  
    6. try:
    7. _fromUtf8 = QtCore.QString.fromUtf8
    8. except AttributeError:
    9. def _fromUtf8(s):
    10. return s
    11.  
    12. try:
    13. _encoding = QtGui.QApplication.UnicodeUTF8
    14. def _translate(context, text, disambig):
    15. return QtGui.QApplication.translate(context, text, disambig, _encoding)
    16. except AttributeError:
    17. def _translate(context, text, disambig):
    18. return QtGui.QApplication.translate(context, text, disambig)
    19.  
    20. class Ui_Dialog(QtGui.QWidget):
    21. def __init__(self):
    22. QtGui.QWidget.__init__(self)
    23. self.setupUi(self)
    24. def setupUi(self, Dialog):
    25. Dialog.setObjectName(_fromUtf8("Dialog"))
    26. Dialog.resize(400, 300)
    27. self.pushButton = QtGui.QPushButton(Dialog)
    28. self.pushButton.setGeometry(QtCore.QRect(30, 40, 75, 23))
    29. self.pushButton.setObjectName(_fromUtf8("pushButton"))
    30. self.lineEdit = QtGui.QLineEdit(Dialog)
    31. self.lineEdit.setGeometry(QtCore.QRect(120, 40, 113, 20))
    32. self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
    33. self.lineEdit_2 = QtGui.QLineEdit(Dialog)
    34. self.lineEdit_2.setGeometry(QtCore.QRect(260, 40, 113, 20))
    35. self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
    36.  
    37. self.retranslateUi(Dialog)
    38. QtCore.QMetaObject.connectSlotsByName(Dialog)
    39.  
    40. def retranslateUi(self, Dialog):
    41. Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
    42. self.pushButton.setText(_translate("Dialog", "PushButton", None))
    43. self.pushButton.clicked.connect(self.changedata)
    44.  
    45.  
    46. def changedata(self):
    47. print ls[0] #this line is just to print out what ls[0] is before it is changed
    48. ls[0] = self.lineEdit #this is where i am stuck as i do not know how to get the line edit data. i,m new to python and qt so forgive me if i'm a bit off
    49. print ls[0] #this line is to print out the new value of ls[0] to see if it changed
    50.  
    51.  
    52. if __name__ == '__main__':
    53. app = QtGui.QApplication(sys.argv)
    54. ex = Ui_Dialog()
    55. ex.show()
    56. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2015
    Posts
    3
    Qt products
    Platforms
    Windows

    Default Re: line edit data input

    figured it out... line 48 ls[0] = self.lineEdit.text()

    Thanks anyway.....

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: line edit data input

    Glad we could help

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. How to set precision for line edit
    By shivendra46d in forum Newbie
    Replies: 4
    Last Post: 26th September 2013, 00:37
  3. Replies: 3
    Last Post: 26th August 2010, 08:57
  4. how to access LINE EDIT'S value
    By BalaQT in forum Qt Programming
    Replies: 8
    Last Post: 20th August 2009, 10:58
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.