我试图编写一个图像显示函数,该函数实例化以下类并在我双击图像时呈现图像,我想通过按ESC关闭窗口,但是它似乎没有用。在复制之前已编写keyPressEvent函数。它以前曾起作用,但在这里不起作用。我很伤心。
let arr = [10, 5, 4, 22, 0, 25, 1000, 1,5555 ,5464564];
// the parseInt are needed because javascript will try to cast your values to string
console.log(arr.sort((a, b) => parseInt(a) - parseInt(b)))
答案 0 :(得分:0)
这是工作代码:
from PySide import QtGui,QtCore
import sys
import os
class ImageLabel(QtGui.QWidget):
def __init__(self, imagePath, parent=None):
super(ImageLabel, self).__init__(parent)
self.imagePath = imagePath
self.initUI()
def initUI(self):
from PIL import Image
pic_size = (Image.open(self.imagePath).width,
Image.open(self.imagePath).height)
self.image_Label = QtGui.QLabel()
self.image_Label.setWindowIcon(QtGui.QIcon(fileconfig.MAIN_ICON))
self.image_Label.resize(pic_size[0] + 50, pic_size[1] + 50)
self.image_Label.setWindowTitle(os.path.basename(self.imagePath))
self.image_Label.setWindowModality(QtCore.Qt.ApplicationModal)
self.image_Label.setPixmap(QtGui.QPixmap(self.imagePath))
self.image_Label.setAlignment(QtCore.Qt.AlignCenter)
# self.image_Label.show()
def keyPressEvent(self, event):
key = event.key()
if key == QtCore.Qt.Key_Escape:
self.close()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
il = ImageLabel('usr/image/img.png')
il.show()
sys.exit(app.exec_())
我只评论了self.image_Label.show()
行,对我来说一切正常