'PyQt5 Image position
I'm trying to position an image in the right place, I was able to place the image on the right and bottom, but it is not in the exact location
I'm trying to position in the exact location x and y
and if anyone knows too, how do I update this image automatically once a new image is inserted into the folder
from PyQt5 import QtCore, QtGui, QtWidgets
import os
import math
class Ui_Form(object):
def setupUi(self, Form):
self.sty_button = "QPushButton {\n" \
...
"}\n"
self.sty_label = "QLabel {\n" \
...
" }\n"
self.sty_angle_label = "QLabel {\n" \
...
" }\n"
self.sty_dots = "QLabel#lblDots {\n" \
...
"}\n"
Form.setObjectName("Form")
Form.resize(710, 418)
Form.setStyleSheet("background-color: rgb(0, 0, 0);")
Form.setFixedSize(Form.size())
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(9, 9, 400, 400))
self.label.setCursor(QtGui.QCursor(QtCore.Qt.CrossCursor))
self.label.setText("")
self.pixmap = QtGui.QPixmap("angle.jpg")
self.pixmapzoom = self.pixmap.scaled(self.pixmap.size() * 2, QtCore.Qt.KeepAspectRatio)
self.label.setPixmap(self.pixmapzoom)
self.label.setObjectName("label")
self.label.mousePressEvent = self.getAngle
self.widget = QtWidgets.QWidget(Form)
self.widget.setGeometry(QtCore.QRect(415, 9, 286, 400))
self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.label_2 = QtWidgets.QLabel(self.widget)
font = QtGui.QFont()
font.setFamily("Calibri")
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.label_2.setStyleSheet(self.sty_angle_label)
self.label_2.setObjectName("label_2")
self.verticalLayout.addWidget(self.label_2)
self.label_3 = QtWidgets.QLabel(self.widget)
font = QtGui.QFont()
...
...
self.folder = ''
self.fullPath = ''
self.isAutoUpdate = False
self.auto_update()
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def change_auto_update(self):
self.isAutoUpdate = False if self.isAutoUpdate else True
print(self.isAutoUpdate)
self.label_5.setText("AUTO UPDATE: ON" if self.isAutoUpdate else "AUTO UPDATE: OFF")
def auto_update(self):
if self.isAutoUpdate:
print(1)
self.files = os.listdir(self.path)
self.file = self.files[-1]
self.fullPath = self.folder + '/' + self.file
self.pixmap = QtGui.QPixmap(self.folder + '/' + self.file)
self.pixmapzoom = self.pixmap.scaled(self.pixmap.size() * 2, QtCore.Qt.KeepAspectRatio)
self.label.setPixmap(self.pixmapzoom)
self.label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignBottom)
else:
print(2)
# self.pick_folder()
def pick_folder(self):
# get the last file from directory
self.path = QtWidgets.QFileDialog.getExistingDirectory(None, 'Select a folder:', 'C:\\Users\\eucri\\Downloads\\PANGUA\\PangyaUS_851\\capture')
if self.path != '':
self.folder = self.path
# get all files from the directory
self.files = os.listdir(self.path)
# get the last file from the directory
self.file = self.files[-1]
# get the last file from the directory
self.fullPath = self.folder + '/' + self.file
self.pixmap = QtGui.QPixmap(self.folder + '/' + self.file)
self.pixmapzoom = self.pixmap.scaled(self.pixmap.size() * 2, QtCore.Qt.KeepAspectRatio)
self.label.setPixmap(self.pixmapzoom)
self.label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignBottom)
def getAngle(self, event):
...
def retranslateUi(self, Form):
....
if __name__ == "__main__":
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

