How to enter Images in a listWidget inside tabWidget
-
@Osama_Billah
You still presumably do not want to add them all as a single string item, as you have done, do you?Don't you want to use https://doc.qt.io/qt-5/qlistwidget.html#addItems for a list, not just one item via
addItem(const QString &label)
? -
@Osama_Billah said in How to enter Images in a listWidget inside tabWidget:
as the images come from a website so every time the number of images and Videos will be change
So what? It's your job to add them to the list. In the code you posted you add strings not images: please read documentation https://doc.qt.io/qt-5/qlistwidget.html#addItems This is to add a list of STRINGS, not images.
Again: take a look at what @anil_arise suggested... -
@jsulm @anil_arise @SGaist oky thank you I'm checking that. as I'm new so It allow me to post after 10 min so sorry for late reply. and another question as I name the tab like tab1, tab2 so how can I call it. because it gave an error " 'QWidget' object has no attribute 'clicked' "
-
@Osama_Billah said in How to enter Images in a listWidget inside tabWidget:
because it gave an error " 'QWidget' object has no attribute 'clicked' "
It's not clear to me what you're trying to achieve. If you want to get a signal if a tab was activated then use https://doc.qt.io/qt-5/qtabwidget.html#currentChanged
-
@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)