Answer the question
In order to leave comments, you need to log in
How to write a "generic" function to work with QLineEdit with different objectName?
I made a GUI for an application with several tabs (Tab)
On several Tabs there is a LineEdit with correspondingly different objectName (like qlineedit_tab1, qlineedit_tab2, etc.) and also buttons for selecting a file
. We need a "universal" function for each of these LineEdit
Now we have this:
def browse_file(self):
file = QtWidgets.QFileDialog.getOpenFileName(self)
self.qlineedit_tab1.setText(file[0])
Answer the question
In order to leave comments, you need to log in
You can pass qlineedit_tab there and it will shove text from there, you just need to make it global, preferably or transfer it to another class, but these are OOP subtleties.
To put it simply, you can take the function out of the class and you get something like this:
def browse_file(qlineedit_tab):
file = QtWidgets.QFileDialog.getOpenFileName(self)
qlineedit_tab.setText(file[0])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question