How to enter Images in a listWidget inside tabWidget
-
@jsulm I wanna to do this
self.tab_2.clicked.connect(self.images_for_tab2)
if the user click on tab_2 it call the own function.
@anil_arise as I write the code it gave an error on invalid syntax. I'm Using python.
Sorry for the trouble but I'm new learner. -
@Osama_Billah https://doc.qt.io/qt-5/qtabwidget.html#currentChanged
If you get errors please post your code and errors. -
self.tab.clicked.connect(self.images_for_tab1) self.retranslateUi(MainWindow) self.tabWidget.setCurrentIndex(2) QtCore.QMetaObject.connectSlotsByName(MainWindow) def images_for_tab1(self): #images in the list will come from a webURL QListWidget * listwidget = new QListWidget() #ui->tabWidget->addTab(listwidget,QIcon(":/img/alert.png"),"NewTab"); QListWidgetItem *item1 = new QListWidgetItem(QIcon("C:/Users/OB/Desktop/DevoMech Project/4.JPG"),"item1") listwidget->addItem(item1) QListWidgetItem *item2 = new QListWidgetItem(QIcon("C:/Users/OB/Desktop/DevoMech Project/5.JPG" , "item2") listwidget->addItem(item2)
-
@jsulm @SGaist @anil_arise @JonB Thanks for your time. I know it's hard for all of you but I'm totally new and have no idea.
-
You are mixing C++ syntax with Python syntax, that's the error you are getting. There's not pointer nor new operator in Python.
-
@SGaist I change it to this
self.item1 = self.QListWidgetItem.QIcon("C:/Users/OB/Desktop/DevoMech Project/4.JPG", "item1") self.listWidget_3.addItem(item1) self.item2 = self.QListWidgetItem.QIcon("C:/Users/OB/Desktop/DevoMech Project/5.JPG", "item2") self.listWidget_3.addItem(item2)
Now the error is
Traceback (most recent call last):
File "C:\Users\OB\Desktop\DevoMech Project\test_for_de.py", line 127, in <module>
ui.setupUi(MainWindow)
File "C:\Users\OB\Desktop\DevoMech Project\test_for_de.py", line 83, in setupUi
self.item1 = self.QListWidgetItem.QIcon("C:/Users/OB/Desktop/DevoMech Project/4.JPG", "item1")
AttributeError: 'Ui_MainWindow' object has no attribute 'QListWidgetItem' -
problem solved. thanks @SGaist @jsulm @anil_arise @JonB I just want to know that every beginner face these problems. or I'm the special one.
-
item1 = QtWidgets.QListWidgetItem(QIcon("path_to_pic"), "Name_of_pic") self.listWidget_2.addItem(item1) item2 = QtWidgets.QListWidgetItem(QIcon("path_to_pic"), "Name_of_pic! self.listWidget_2.addItem(item2)
-
@Osama_Billah said in How to enter Images in a listWidget inside tabWidget:
I just want to know that every beginner face these problems. or I'm the special one.
At the beginning we are all beginners :-)
-
Off topic replies forked to here:
-
Thanks for your response. One more thing how to convert these images horizontally and increase the size. @SGaist @jsulm @anil_arise @JonB
-
this is the code. I used QIcon the one @anil_arise suggest
self.tabWidget.setIconSize(QtCore.QSize(32, 32)) QtWidgets.QListWidgetItem.setLayoutDirection(QtCore.Qt.LeftToRight)