Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- from PyQt5 import QtCore, QtGui
- from PyQt5.QtWidgets import QApplication,QWidget,QGridLayout,QScrollArea,QLabel
- import os
- class ImageViewer(QWidget):
- #gridLayout_2 = ""
- def __init__(self, parent=None):
- QWidget.__init__(self, parent)
- self.gridLayout = QGridLayout(self)
- self.gridLayout.setObjectName("gridLayout")
- self.scrollArea = QScrollArea(self)
- self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
- self.scrollArea.setWidgetResizable(True)
- self.scrollArea.setObjectName("scrollArea")
- self.scrollAreaWidgetContents = QWidget(self.scrollArea)
- self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 344, 487))
- self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
- self.gridLayout_2 = QGridLayout(self.scrollAreaWidgetContents)
- #self.gridLayout_2.setObjectName("gridLayout_2")
- self.scrollArea.setWidget(self.scrollAreaWidgetContents)
- self.gridLayout.addWidget(self.scrollArea, 0, 0, 1, 1)
- def populate(self, pics, size, flags=Qt.KeepAspectRatioByExpanding):
- row = col = 0
- for pic in pics:
- label = QLabel(self)
- try:
- pixmap = QtGui.QPixmap(pic)
- pixmap = pixmap.scaled(size, flags)
- label.setPixmap(pixmap)
- self.gridLayout_2.addWidget(label, row, col)
- col += 1
- #if col % imagesPerRow == 0:
- #row += 1
- #col = 0
- except:
- pass
- # self.retranslateUi()
- #QtCore.QMetaObject.connectSlotsByName(self)
- #def retranslateUi(self):
- #self.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
- app = QApplication([])
- exm = ImageViewer()
- pics = 'C:/Users/Marco/PycharmProjects/scroll_images/'
- listdir = os.listdir(pics)
- lista = []
- for pic in listdir:
- lista.append(pics + pic)
- exm.populate(lista, QSize(100, 10))
- exm.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement