Trying_hard
Trying_hard

Reputation: 9501

PyQt4 QLineEdit()

I am trying to make a simple GUI that I want to use in an overall bigger program, but what I am trying to do is use QlineEdit in a table and once the QlineEdit is changed in the example to anything I can pick up that change and save that change in a list that I will iterate over later.

from PyQt4 import QtCore, QtGui
import sys

app = QtGui.QApplication([])
table = QtGui.QTableWidget(6,2)

tableItem = QtGui.QLineEdit()
tableItem.setText( "Testing" )
table.setCellWidget(0, 1, tableItem )

So in the example I want to be able to change "Testing" to anything, and once that change takes place. I am lost on how to pick up the change I have tried playing around with textChanged() but can't get it to work.

Upvotes: 0

Views: 3240

Answers (1)

zhangxaochen
zhangxaochen

Reputation: 34017

from PyQt4 import QtCore, QtGui
import sys

app = QtGui.QApplication([])
table = QtGui.QTableWidget(6,2)

tableItem = QtGui.QLineEdit()
tableItem.setText( "Testing" )

def onTextChanged(text):
    print 'onTextChanged', text
    pass

tableItem.textChanged.connect(onTextChanged)
table.setCellWidget(0, 1, tableItem )
table.show()
app.exec_()

btw, I think it's better to arrange the GUI using qt designer...

Upvotes: 1

Related Questions