How to get name of image from QlistWidget
-
Hi I have different images in QListWidget. I want that If I clicked on the images it show me the actual name.
def add_images_to_TabWIdget(self): path = "C:/Users/OB/Desktop/DevoMech Project/data/thumdnail/" print(path) print(self.entries) filename = [] i=0 for entry in self.entries: filename.append(entry) print(filename[i]) #entry = self.entries # print(entry) # a = ("," .join(entry)) # print(a) item1 = QtWidgets.QListWidgetItem(QIcon(path + filename[i]), filename[i]) self.dlistWidget.addItem(item1) return item1 i += 1 def item_images_clicked(self , item1): print("click {}".format(item1.text())) -
You have to store the name by yourself in the QListWidgetItem e.g. with QListWidgetItem::setData()
-
You have to store the name by yourself in the QListWidgetItem e.g. with QListWidgetItem::setData()
@Christian-Ehrlicher I want to take the image name from the list
-
You have to store the name by yourself in the QListWidgetItem e.g. with QListWidgetItem::setData()
@Christian-Ehrlicher all the names are store in the list. and from that list i input the images with the name. and I want that if someone clicked on that image it print the image name
-
@Osama_Billah said in How to get name of image from QlistWidget:
I want to take the image name from the list
Then store the index to the list in QListWidgetItem::data() so you can access it later on.
-
Hi I have different images in QListWidget. I want that If I clicked on the images it show me the actual name.
def add_images_to_TabWIdget(self): path = "C:/Users/OB/Desktop/DevoMech Project/data/thumdnail/" print(path) print(self.entries) filename = [] i=0 for entry in self.entries: filename.append(entry) print(filename[i]) #entry = self.entries # print(entry) # a = ("," .join(entry)) # print(a) item1 = QtWidgets.QListWidgetItem(QIcon(path + filename[i]), filename[i]) self.dlistWidget.addItem(item1) return item1 i += 1 def item_images_clicked(self , item1): print("click {}".format(item1.text()))add line in add_images_to_TabWIdget(self):
dlistWidget.itemClicked.connect(item_images_clicked)