我试图将图像从文件夹/目录加载到标签中,然后再添加到网格布局中。之后,我想使用拖放功能将所选图像从pyqt5应用程序拖动到Microsoft Word应用程序。是代码
import os
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import QPixmap, QCursor
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(862, 574)
self.centralwidget = QtWidgets.QWidget(MainWindow)
#path to folder
folderPath = "data\images\collections"
#lopping through the folder to image names
for row,file in enumerate(os.listdir(folderPath)):
#setting number of cols per row
for cols in range(4):
lab = QtWidgets.QLabel(self.scrollAreaWidgetContents_9)
pixmap = QPixmap(os.path.join(folderPath, file))
#adding image to label
lab.setPixmap(pixmap)
lab.setScaledContents(True)
#adding labels to grid layout
self.gridLayout_2.addWidget(lab, row, cols, 1, 1)