我有一个显示图像的小部件。使用鼠标双击图像时,它将打开一个新窗口,其中包含调整大小的图像。每次双击,它都会继续打开其他窗口。目前这有效。
我现在正在尝试使用multiprocessing
在新的单独进程中打开每个窗口。新窗口不会将信息传递回父进程,因此我只希望新窗口完全独立。我该如何实现?
from PyQt4 import QtGui, QtCore
import multiprocessing as mp
import sys
class ImageZoom(QtGui.QMainWindow):
def __init__(self, parent, image_file):
super(ImageZoom, self).__init__(parent)
self.image_file = image_file
self.picture = QtGui.QLabel()
self.pixmap = QtGui.QPixmap(self.image_file)
self.pixmap = self.pixmap.scaled(900,900, QtCore.Qt.KeepAspectRatio)
self.picture.setPixmap(self.pixmap)
self.setCentralWidget(self.picture)
class Window(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.image_file = '1.jpeg'
self.picture = QtGui.QLabel()
self.pixmap = QtGui.QPixmap(self.image_file)
self.picture.setPixmap(self.pixmap)
self.setCentralWidget(self.picture)
self.windows = []
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.length)
self.timer.start(1000)
def length(self):
print(len(self.windows))
def mouseDoubleClickEvent(self, event):
print('double click')
dialog = ImageZoom(self, self.image_file)
self.windows.append(dialog)
dialog.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())