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?
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?
So is this the same LineEdit object? What would the index do?
Or are these three LineEdit objects?
Cheers,
_
Sorry if my code was confusing. I need a subclassed LineEdit with an index attribute that I can set when the object is created. I would like to access it with LineEdit(index).text()
Is this possible?
I still don't understand what that "index" attribute is for.
It sounds like you want to have a list of line edits.
Lets try this visually: do you have one line edit or more than one?
Cheers,
_
It is for a column of LineEdits. I need to subclass one (with an index) and then make lots of copies with individual index numbers.
What does the class do with the index number?
Cheers,
_
Sounds to me like you are confusing how your program keeps track of multiple QLineEdit instances with the QLineEdit instances themselves. If you simply stick the QLineEdit pointers into a vector as you create them, then the index in the vector -is- the index of the QLineEdit. If all of your QLineEdit instances are connected to the same slot, then you can use the QObject::sender() method in the slot to get the pointer to the specific QLineEdit instance that sent the signal, and then search the vector to get the index.It is for a column of LineEdits. I need to subclass one (with an index) and then make lots of copies with individual index numbers.
Or if your "index" is non-sequential, you can make a QMap< QWidget *, int > to map the QLineEdit pointer to any integer.
Or you can use QSignalMapper to associate each QLineEdit instance with an integer.
There are lots of ways to do what I think you are trying to do without having to make a custom widget.
The class doesn't do anything with the index. I have a routine that creates a grid consisting of rows with a textbox followed by some labels. They are created in code using a series of for loops. If I can create a subclassed LineEdit(index) I will be able to use an existing routine written in VB6.
Added after 6 minutes:
Thanks for the reply. I don't understand what you said so it doesn't help much. What is a vector? I appreciate the different methods to do what you think that I want to do, but what I really want is to know if it is possible to subclass a QLineEdit with an index and access it in this format: LineEdit(index) not LineEdit.index
Last edited by nlgootee; 3rd May 2016 at 22:50.
Then why does it need the index?
Ok, that is possible with normal QLineEdits as well.
So what does the VB6 line edit object use the index for?
There must be a reason why the line edit object itself needs to know which index it stands for.
A vector is a linear container, like a list or array.
Its elements can be accessed by index.
Of course, you can store arbitrary data in a class, so creating a subclass of QLineEdit that stores an integer is possible.
The first creates an object of class LineEdit and passes "index" to its constructor.
The second accesses an object called LineEdit and accesses its "index" property.
As d_stranz said and what I am trying to find out since several iterations is if you need the index inside the object or if you want to access several objects by index.
Because the code snippet suggest the latter but you keep insisting on the former.
Cheers,
_
That is what I need. I am creating a screen displaying 1650 inventory items. The lineedit is used to enter a quantity for an order. When a lineedit has a number entered, the index is used to access the information in the corresponding labels in that row (using the same index) and passing that to a page where the invoice is displayed and a routine that prints a hard copy. I want to create a LineEdit, assign an index and place it on a form in a loop that will create a grid with all 1650 items.
For the access you put the line edit in a list, vector or array, whatever the preferred data structure for that is in Python.
If you really need to store the index value in the object as well, just call setProperty() on it, that will create a dynamic property with any name you choose.
Cheers,
_
Bookmarks