A PyQt5/PySide2 widget for displaying images
Project description
QImageWidget Documentation
QImageWidget is a Python library that provides a widget for displaying images in a PyQt5 GUI. The library allows you to easily load images and scale them to fit the widget.
Installation
You can install QImageWidget by cloning the GitHub repository:
git clone https://github.com/RedEnder666/QImageWidget
Methods
| Method | Arguments | Description |
|---|---|---|
| init(self, parent, img='') | parent: QWidget, img: str | Initializes a new QImageWidget object with an optional image. |
| setImage(self, img) | img: str | Sets the image for the QImageWidget. |
| setScale(self, size, aspectRatioMode=Qt.IgnoreAspectRatio) | size: tuple, aspectRatioMode: Qt.AspectRatioMode | Scales the image to the specified size with the specified aspect ratio mode. |
# Usage Here is an example of how to use QImageWidget:
import sys
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton
from QImageWidget import QImageWidget
class ImageWidget(QWidget):
def __init__(self):
super().__init__()
# Create a QImageWidget object
self.imageWidget = QImageWidget(self)
# Set the image
self.imageWidget.setImage('example.jpg')
# Set the scaling
self.imageWidget.setScale((400, 400), Qt.KeepAspectRatio)
# Create a button to update the image
self.btnUpdate = QPushButton('Update', self)
self.btnUpdate.clicked.connect(self.updateImage)
# Create a vertical layout and add the widgets to it
layout = QVBoxLayout(self)
layout.addWidget(self.imageWidget)
layout.addWidget(self.btnUpdate)
def updateImage(self):
# Update the image
self.imageWidget.setImage('example2.jpg')
if __name__ == '__main__':
app = QApplication(sys.argv)
# Create an ImageWidget object
widget = ImageWidget()
widget.show()
sys.exit(app.exec_())
This example creates a QImageWidget object, sets an image, sets scaling, and adds the widget to a vertical layout along with a button to update the image. When the button is clicked, the updateImage method is called, which changes the image to a different one. The code also creates a QApplication object and displays the widget on the screen.
Documentation was made by ChatGPT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file QImageWidget-1.0.3.tar.gz.
File metadata
- Download URL: QImageWidget-1.0.3.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
208212be721c91c7985c03424a82e9eacb36e2b2984db5fd2c155cde3ecd3ba9
|
|
| MD5 |
d47ed463f8a784b6cbd885069f91a20d
|
|
| BLAKE2b-256 |
d287175c04a42d687a62235d85edffef1bed8bb67e273d3daf630c4ad7ef351b
|