简体   繁体   中英

QListWidget how to get the signal emitted?

    with open('championships.txt', 'r') as rf:
        lines = rf.readlines()
        for line in lines:
            champioshiplist.addItem(QListWidgetItem(line.strip()))

    champioshiplist.doubleClicked.connect(self.listclisc)

def listclisc(self):
    print('OK')

I populated the Qwidgetlist from a txt file, but I am not able to get the clicked value from the list, in the example the printing works but how can i get text of the list? I am not able to save the clicked item. i would like to do

    def listclisc(self):
      text = championshiplist.... value 

but the function doesn't see the Qwidgetlist. I am new in Python and do not really understand how to do

The doubleClicked signal sends the associated QModelIndex that has the information you require:

def listclisc(self, index):
    print('OK', index.data())

Similarly you can use the itemDoubleClicked signal:

    champioshiplist.itemDoubleClicked.connect(self.listclisc)

def listclisc(self, item):
    print('OK', item.text())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM