PyQt中的标记系统

时间:2016-02-01 14:55:57

标签: python user-interface pyqt pyqt4 qpixmap

您好我正在尝试在PyQt4中创建一个GUI,用户可以在其中标记从视频/图像中提取的面部。我有一个文件夹,我已经存储了所有的面孔(图像)。

     pic4.setPixmap(QtGui.QPixmap(os.getcwd() + "/faces/Testimg3.png"))
pic5 = QtGui.QLabel(window)
pic5.setGeometry(500,200,70,70)
pic5.setPixmap(QtGui.QPixmap(os.getcwd() + "/faces/Testimg4.png"))
pic6 = QtGui.QLabel(window)
pic6.setGeometry(500,340,70,70)
pic6.setPixmap(QtGui.QPixmap(os.getcwd() + "/faces/Testimg5.png"))
te1 = QtGui.QTextEdit(window)
te1.setGeometry(160,70,140,30)
te2 = QtGui.QTextEdit(window)
te2.setGeometry(160,210,140,30)
te3 = QtGui.QTextEdit(window)
te3.setGeometry(160,350,140,30)

目前我有这样的事情。 Pix-maps后跟文本编辑以获取标签。这个我已经硬编码显示我的文件夹中的6个图像以及文本编辑。任何人都可以指导我如何使这个动态,即显示应该显示文件夹中的所有图像以及文本编辑。 注意:文件夹中的图像数量可能会改变。

1 个答案:

答案 0 :(得分:0)

一个非常简单的方法是使用QTableWidget或QTreeWidget。

获取文件夹中的图像列表,然后将每个项目添加到表格或树中。

tree = QTreeWidget()
tree.setHeaderLabels(['Path', 'Image'])

paths = ['/path/one', '/path/two']
for path in paths:
    pixmap = QPixmap(path)
    label = QLabel()
    label.setPixmap(pixmap)
    item = QTreeWidgetItem()
    item.setText(0, path)
    tree.addTopLevelItem(item)
    tree.setItemWidget(item, 1, label)