【发布时间】:2021-12-20 10:10:28
【问题描述】:
我想实现一个图形用户界面,每次按键事件发生时图像都会更新,这是一个尝试,但图像没有更新。
class Test(QMainWindow):
def __init__(self, path):
super().__init__()
self.path = path
self.sliceno = 40
self.initUI()
def vol(self):
slices = [1,2,3,4,5,6]
return slices
def keyPressEvent(self, event):
key = event.key()
if event.key() == QtCore.Qt.Key_Q: #Event
self.sliceno = self.sliceno + 1
def initUI(self):
im = np.uint8(self.vol()[self.sliceno]) #should change the index when 'q' pressed
qimage = QImage(im, im.shape[1], im.shape[0], QImage.Format_Grayscale8)
pixmap = QPixmap(qimage)
pixmap_label.setPixmap(pixmap)
self.setCentralWidget(pixmap_label)
self.show()
【问题讨论】: