pyqt弹出框自适应位置,图片设置最大宽高,同比例缩放。
调用代码:
dialog = QimgDialog(params)
dialog.setWindowModality(Qt.ApplicationModal) # 设置窗口的属性为ApplicationModal模态,用户只有关闭弹窗后,才能关闭主界面
dialog.exec_()
qt_dialog.py
import os
from PyQt5 import QtCore
from PyQt5.QtCore import pyqtSignal, Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QDialog, QApplication, QLabel, QPushButton, QGridLayout, QVBoxLayout
class QimgDialog(QDialog):
rightClick = pyqtSignal(object)
def __init__(self,params, parent=None):
super(QimgDialog, self).__init__(parent)
self.initUI(params)
def initUI(self,params):
image_path, px, py = params
self.showImage = QPixmap(image_path)
desktop = QApplication.desktop()
desk_width = desktop.width()
desk_height