如何使用PyQT4(快速)缩略图300个图像?

2024-04-23 16:42:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个图书装订应用程序,为了使它美观,我在你拖入的每一页上都添加了一个缩略图。它工作得很好,但唯一的问题是,当我拖入整本书(即400幅图像)时,它会完全冻结,直到完成为止。在

下面是我的简单删除代码:

  def fileDropped(self, file):
    f = str(file[-1])

    if os.path.splitext(f)[1][1:] != 'tif':
      reply = QtGui.QMessageBox.question(self, 'Message', 'All files must be TIF images. Would you like me to convert a copy of your file to the TIF format?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)

      if reply == QtGui.QMessageBox.Yes:
        if not os.path.exists('./djvu_backup/'):  os.mkdir('./djvu_backup/')



        if f not in self.getChildren(self.ui.pageList):   # It's a custom method. It does what it looks like it does.
          icon = QtGui.QIcon(f)
          pixmap = icon.pixmap(72, 72)
          icon = QtGui.QIcon(pixmap)
          item = QtGui.QListWidgetItem(f, self.ui.pageList)
          item.setIcon(icon)
          item.setStatusTip(f)

        return True

{1}正如你在问题中看到的一样。每次调用方法时,我都必须从droppedfiles数组中选择最后一个元素,因为它是针对每个被删除的文件而调用的,即使它们是一次被删除的。有什么原因/解决方法吗?在

谢谢你!在


Tags: topathselfifositemreplylike
2条回答

你可以试着加快钉钉子的速度,但这只会增加你在发现问题之前可以放下的书的尺寸。答案是要么只缩略显示页面,要么将缩略图放到背景线程中,然后在每次完成时更新显示。在

我知道这很简单,但是你有没有考虑过使用QProgressBar,这样用户就可以看到程序在被冻结时仍在处理中吗?在

相关问题 更多 >