I want to be able to differentiate whether a user selected an item of my QListWidget, because he may also have entered a free text instead. I tried by checking the currentIndex of the QListWidget, but it seems like the currentIndex function does not return None as I have been hoping. Is there an easy way or may I need to implement a onSelectionChanged method to know whether user selected an item? If I have to go the "method implementation" way, how could the user "unselect" his selection?
def ok_clicked(self):
self.sig_1_index = self.dialog_layout.data_series_sig_list_1.currentIndex()
self.sig_2_index = self.dialog_layout.data_series_sig_list_2.currentIndex()
self.text_2 = self.dialog_layout.data_series_operator.currentText()
if self.sig_1_index != None: #doesnt work
if self.sig_2_index != -1: #also doesnt work
self.text_1 = self.dialog_layout.data_series_sig_list_1.itemFromIndex(self.sig_1_index).text()
self.text_3 = self.dialog_layout.data_series_sig_list_2.itemFromIndex(self.sig_2_index).text()
else:
self.text_1 = self.dialog_layout.data_series_filter_1.toPlainText()
self.text_3 = self.dialog_layout.data_series_sig_list_2.itemFromIndex(self.sig_2_index).text()
else:
if self.sig_2_index != None:
self.text_1 = self.dialog_layout.data_series_sig_list_1.itemFromIndex(self.sig_1_index).text()
self.text_3 = self.dialog_layout.data_series_filter_2.toPlainText()
else:
self.text_1 = self.dialog_layout.data_series_filter_1.toPlainText()
self.text_3 = self.dialog_layout.data_series_filter_2.toPlainText()
print(self.text_1 + self.text_2 + self.text_3)