【问题标题】:How do I (quickly) thumbnail 300 images with PyQT4?我如何(快速)使用 PyQT4 缩略图 300 张图像?
【发布时间】:2011-06-03 03:04:57
【问题描述】:

我正在(仍在)开发书籍装订应用程序,为了使其美观,我为您拖入的每个页面添加了一个缩略图。它工作得很好,但唯一的问题是当我拖动在整本书(即 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

另外,正如您在代码中看到的那样,作为一个附带问题,f = str(file[-1])。每次调用该方法时,我都必须从删除的文件数组中选择最后一个元素,因为每个删除的文件都会调用它,即使它们一次全部删除。这有什么原因/解决方法吗?

谢谢!

【问题讨论】:

标签: python drag-and-drop thumbnails pyqt4


【解决方案1】:

您可以尝试加快缩略图的速度,但这只会增加您可能在发现问题之前放下的书的大小。答案是仅在显示页面时对其进行缩略图,或者将缩略图降级到后台线程并在每个完成时更新显示。

【讨论】:

  • 我认为后者可能是更好的选择。有没有办法用 Python 做到这一点?
【解决方案2】:

我知道这很简单,但您是否考虑过使用 QProgressBar 以便用户可以看到程序仍在处理时,它似乎被冻结了?

【讨论】:

  • 回复有点晚了,但我已经在QThread 中实现了这一点,并带有状态消息和所有好东西;)
猜你喜欢
  • 2013-04-03
  • 1970-01-01
  • 2023-03-25
  • 2020-12-18
  • 2013-08-08
  • 2020-12-14
  • 2014-05-26
  • 2013-02-04
  • 1970-01-01
相关资源
最近更新 更多