logo
down
shadow

Scrollable QLabel image in PyQt5


Scrollable QLabel image in PyQt5

Content Index :

Scrollable QLabel image in PyQt5
Tag : python , By : Fernando
Date : November 24 2020, 05:44 AM

I wish this helpful for you When you create a QScrollArea with Qt Designer a widget called scrollAreaWidgetContents is created and this is the one inside the QScrollArea and therefore its size is used to establish what is shown in the scrollbar, in your case imageLabel is the son of scrollAreaWidgetContents it is observed but scrollAreaWidgetContents does not know the size of imageLabel, so in these cases you must use the layouts so that the minimum size of the scrollAreaWidgetContents matches that of the imageLabel.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic


class photo(QtWidgets.QDialog):
    def __init__(self,parent=None):
        super(photo, self).__init__(parent)
        uic.loadUi('EmployeeUpdate.ui', self)
        self.btn.clicked.connect(self.attachImage)

    def attachImage(self):
        lay = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
        lay.setContentsMargins(0, 0, 0, 0)
        lay.addWidget(self.imageLabel)
        path = "G:/Data Analytics/Resnsol Face Recognition/a.jpg"
        pixMap = QtGui.QPixmap(path)
        self.imageLabel.setPixmap(pixMap)
        self.imageScrollArea.setWidgetResizable(True)
        self.imageLabel.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)


def main():
    app = QtWidgets.QApplication(sys.argv)
    window = photo()
    #window.attachImage()
    window.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

pyqt5 trying to use QGridLayout to organise my QLabel, QLineEdit, QPushButton, and "Pop-up" QLabel


Tag : python-3.x , By : Dominique Vocat
Date : March 29 2020, 07:55 AM
it fixes the issue You call the createGridLayout method earlier than you define the variables used in it.
import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QHBoxLayout, 
                            QVBoxLayout, QPushButton, QLabel, QLineEdit, 
                            QGridLayout, QGroupBox, QDialog)
from PyQt5.QtCore import pyqtSlot

class Window(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        self.setWindowTitle("Project PiBu!!")

#        self.createGridLayout()
#        self.windowLayout = QVBoxLayout()
#        self.windowLayout.addWidget(self.horizontalGroupBox)
#        self.setLayout(self.windowLayout)

        self.game_name      = QLabel("Game Name:", self)
        self.game_line_edit = QLineEdit(self)
        self.search_button  = QPushButton("Search", self)
        self.search_button.clicked.connect(self.on_click)
        self.game = QLabel(self)

        self.createGridLayout()                                 # < --
        self.windowLayout = QVBoxLayout()                       # < --
        self.windowLayout.addWidget(self.horizontalGroupBox)    # < --
        self.setLayout(self.windowLayout)                       # < --

        self.show()

    def createGridLayout(self):
        self.horizontalGroupBox = QGroupBox()
        self.layout = QGridLayout()
        self.layout.setColumnStretch(1, 4)
        self.layout.setColumnStretch(2, 4)

        # AttributeError: 'Window' object has no attribute 'game_name'
        self.layout.addWidget(self.game_name, 0, 0)

        self.layout.addWidget(self.game_line_edit, 0, 1)
        self.layout.addWidget(self.search_button, 0, 2)
        self.layout.addWidget(self.game, 1, 0)

        self.horizontalGroupBox.setLayout(self.layout)          # +++ self.

    @pyqtSlot()
    def on_click(self):
        self.game.setText(self.game_line_edit.text())

if __name__ == '__main__':

    app = QApplication(sys.argv)
    win = Window()
    sys.exit(app.exec_())

Draw over image in a QLabel with PyQt5


Tag : python , By : Tim
Date : March 29 2020, 07:55 AM
around this issue Do not draw inside a widget outside of the paintEvent(). This is not supported by Qt.
You may draw on a QImage or QPixmap instead, and then in paintEvent() of your widget, draw that image. Images can be initialized with all pixels transparent as well, if you like to composite several images (background+drawing) instead of drawing on the background directly.

PyQt5 Displaying an Image using a QLabel from Memory


Tag : python , By : janik
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can load the image from memory using loadFromData
In your example, the following should work:
try:
    img_data = load_operation_that_might_fail()
except:
    myLabel.setText("no image available")
    return

pixmap = QPixmap()
myLabel.loadFromData(img_data, 'png')
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QLabel, QApplication)
from PyQt5.QtGui import QPixmap
import sys


class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        hbox = QHBoxLayout(self)
        pixmap = QPixmap()
        pixmap.loadFromData(self.load_operation_that_might_fail(), 'png')

        lbl = QLabel(self)
        lbl.setPixmap(pixmap)

        hbox.addWidget(lbl)
        self.setLayout(hbox)

        self.setWindowTitle('Example')
        self.show()


    def load_operation_that_might_fail(self):
        with open('c:/temp/test.png', 'rb') as f:
            return f.read()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

Pyqt5 QLabel with image at top and text at bottom


Tag : python , By : pacorro2000
Date : March 29 2020, 07:55 AM
will help you I am trying to create a PyQt5 - QLabel with both image and text. I would like to have a text at the bottom of the image. Below is a part of the code , You have to use 2 QLabel in a QVBoxLayout:
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget


class Window(QWidget):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        pixmap_label = QLabel(
            pixmap=QPixmap("/home/moh/Documents/My_GUI/Icons/Delete.png")
        )
        text_label = QLabel(text="delete")

        lay = QVBoxLayout(self)
        lay.addWidget(pixmap_label, alignment=Qt.AlignCenter)
        lay.addWidget(text_label, alignment=Qt.AlignCenter)


if __name__ == "__main__":

    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())

How do I align centre image on QLabel in PyQt5?


Tag : python , By : user160048
Date : March 29 2020, 07:55 AM
this will help The QPixmap is centered on the QLabel, but the problem is that the QLabel is not centered with respect to the window. So you should center the widget by changing to:
layout.addWidget(label_img, alignment=Qt.AlignCenter)
Related Posts Related QUESTIONS :
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com