Reputation: 31
My Question is regarding QCompleter, Following minimum working code using QCompleter executes succesfully, and the output is also given below,
import sys
from PyQt5.QtWidgets import (
QApplication,
QCompleter,
QLineEdit,
QVBoxLayout,
QWidget
)
import pandas as pd
data2={'Name': ['Tom', 'John','Pakistan',"word1","word2","Ten"],
'Description': ["Cruise",
"cena",
"Capital is Islamabad",
"synonum of word1",
"example of word2",
"10",
]}
df=pd.DataFrame(data2)
class mywin(QWidget): # doesnot work with QMainWindow
def __init__(self):
super(mywin,self).__init__()
self.initUI()
def initUI(self):
vbox=QVBoxLayout()
self.setWindowTitle('application')
self.setGeometry(200,200,400,200)
self.l=QLineEdit()
completer=QCompleter(df.Name)
self.l.setCompleter(completer)
vbox.addWidget(self.l)
self.setLayout(vbox)
def mymain():
app = QApplication(sys.argv)
win=mywin()
win.show()
sys.exit(app.exec_())
if __name__=='__main__':
mymain()
and the output is shown below
Now, I want QCompleter to show the second column which is 'Description', It should find elements based on 1st column but suggest the corresponding second column entry. For Example: If 'Tom' is typed/selected, the QCompleter should show 'Cruise' only, if "John" is selected then the QCompleter should enter "Cena" only in the QLineEdit QObject (QLineEdit should show Cena only when John is typed/selected, Cruise only when Tom is typed/selected), and same for all other entries.
Please Note: that completer=QCompleter(df.Description) is not the answer i am looking for.
Upvotes: 0
Views: 190