Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. from PyQt5.QtCore import *
  2. from PyQt5.QtGui import *
  3. from PyQt5 import QtCore, QtGui
  4. from PyQt5.QtWidgets import QApplication,QWidget,QGridLayout,QScrollArea,QLabel
  5.  
  6. import os
  7.  
  8.  
  9. class ImageViewer(QWidget):
  10. #gridLayout_2 = ""
  11.  
  12. def __init__(self, parent=None):
  13. QWidget.__init__(self, parent)
  14.  
  15. self.gridLayout = QGridLayout(self)
  16. self.gridLayout.setObjectName("gridLayout")
  17.  
  18. self.scrollArea = QScrollArea(self)
  19. self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
  20. self.scrollArea.setWidgetResizable(True)
  21. self.scrollArea.setObjectName("scrollArea")
  22.  
  23. self.scrollAreaWidgetContents = QWidget(self.scrollArea)
  24. self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 344, 487))
  25. self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
  26.  
  27. self.gridLayout_2 = QGridLayout(self.scrollAreaWidgetContents)
  28. #self.gridLayout_2.setObjectName("gridLayout_2")
  29.  
  30. self.scrollArea.setWidget(self.scrollAreaWidgetContents)
  31. self.gridLayout.addWidget(self.scrollArea, 0, 0, 1, 1)
  32.  
  33. def populate(self, pics, size, flags=Qt.KeepAspectRatioByExpanding):
  34. row = col = 0
  35. for pic in pics:
  36. label = QLabel(self)
  37. try:
  38. pixmap = QtGui.QPixmap(pic)
  39. pixmap = pixmap.scaled(size, flags)
  40. label.setPixmap(pixmap)
  41. self.gridLayout_2.addWidget(label, row, col)
  42. col += 1
  43. #if col % imagesPerRow == 0:
  44. #row += 1
  45. #col = 0
  46. except:
  47. pass
  48.  
  49. # self.retranslateUi()
  50. #QtCore.QMetaObject.connectSlotsByName(self)
  51.  
  52. #def retranslateUi(self):
  53. #self.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
  54.  
  55.  
  56. app = QApplication([])
  57. exm = ImageViewer()
  58. pics = 'C:/Users/Marco/PycharmProjects/scroll_images/'
  59. listdir = os.listdir(pics)
  60.  
  61. lista = []
  62. for pic in listdir:
  63. lista.append(pics + pic)
  64.  
  65. exm.populate(lista, QSize(100, 10))
  66. exm.show()
  67. app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement