两个图像在彼此之下QGridLayout PyQt

时间:2016-06-05 13:40:30

标签: python pyqt pyqt4

我想使用QGridLayout来构建我的GUI。需要有两个图像在彼此的顶部,我只能看到顶部的图像。我制作了两个QLabel,将它们调整到适当的大小,并将QPixmap设置为QLabel。在此之后,我将标签设置在位置(1,1)和(2,1),但只有顶部显示。我是PyQt4的新手,我真的不知道这是怎么发生的。如果我交换它们,则另一个显示,以便可以访问图像。

identifyLayout = QtGui.QGridLayout()

frontIdentifyImg = QtGui.QLabel()
frontIdentifyImgPixmap = QtGui.QPixmap(os.path.realpath('../GUI/front_image_identify.png'))
frontIdentifyImg.resize(450,450)
frontIdentifyImg.setPixmap(frontIdentifyImgPixmap)
identifyLayout.addWidget(frontIdentifyImg, 1, 1)

frontMatchImg = QtGui.QLabel()
frontMatchImgPixmap = QtGui.QPixmap(os.path.realpath('../GUI/front_image_match.png'))
frontMatchImg.resize(450,450)
frontMatchImg.setPixmap(frontMatchImgPixmap)
identifyLayout.addWidget(frontIdentifyImg, 2, 1)

1 个答案:

答案 0 :(得分:0)

我是个白痴,我在布局中添加了错误的小部件。最后一行应该是:

identifyLayout.addWidget(frontMatchImg, 2, 1)

另外,调整大小不是必需的,索引从0开始。

相关问题