I need to subclass a PyQt5 QLineEdit so that it has an index, such that I could access it by:
stringvariable = LineEdit(0).text()
stringvariable = LineEdit(1).text()
stringvariable = LineEdit(2).text()
Is this possible?
Why don't you make a list of your LineEdits?
mylist = [QLineEdit(), QLineEdit(), QLineEdit()]
index = 0
string = mylist[index].text()
print(string)
Or, if you really need to make a subclass
class MyLineEdit(QLineEdit):
all_instances = {}
def __init__(self, index, *args, **kwargs):
super(MyLineEdit, self).__init__(*args, **kwargs) # call to superclass
MyLineEdit.all_instances[index] = self # add this instance to MyLineEdit.all_instances
def LineEdit(index):
return MyLineEdit.all_instances[index]
To use it, you can simply do:
# Make an instance
edit = MyLineEdit(123)
string = LineEdit(123).text()
# which is equivalent to using
string = edit.text()