Пример #1
0
 def setup_image_message_box(self):
     MAX_WIDTH = MAX_HEIGHT = 300
     self.messageBox = QtWidgets.QLabel()
     img_url = url_join(self.chat_window.mscolab_server_url,
                        self.attachment_path)
     data = requests.get(img_url).content
     image = QtGui.QImage()
     image.loadFromData(data)
     self.message_image = image
     width, height = image.size().width(), image.size().height()
     if width > height and width > MAX_WIDTH:
         image = image.scaledToWidth(MAX_WIDTH)
     elif height > width and height > MAX_HEIGHT:
         image = image.scaledToHeight(MAX_HEIGHT)
     self.messageBox.setPixmap(QtGui.QPixmap(image))
     self.messageBox.setContentsMargins(0, 5, 0, 5)
     self.messageBox.show()
Пример #2
0
 def display_uploaded_img(self, file_path):
     self.messageText.clear()
     image_uri = QtCore.QUrl(f"file://{file_path}")
     image = QtGui.QImage(QtGui.QImageReader(file_path).read())
     self.messageText.document().addResource(
         QtGui.QTextDocument.ImageResource, image_uri,
         QtCore.QVariant(image))
     img_width, img_height = self.get_img_dimensions(image)
     image_format = QtGui.QTextImageFormat()
     image_format.setWidth(img_width)
     image_format.setHeight(img_height)
     image_format.setName(image_uri.toString())
     cursor = self.messageText.textCursor()
     cursor.movePosition(QtGui.QTextCursor.End,
                         QtGui.QTextCursor.MoveAnchor)
     cursor.insertImage(image_format)
     self.messageText.setReadOnly(True)