I am creating a label with a pixmap in a cell of a QTableWidget, and I want to be able to "zoom" in and out of the table. I accomplish this by scaling the pixmap with .scaled(width, height)
which works totally fine, however once the pixmap is scaled down I can not scale it back up again and maintain the original resolution. In other words once it has drawn to a smaller size I no longer have those pixels for later use, so when I scale it up I'm re-sampling the image.
How can I make it so that I am able to "zoom" in and then back out again of a pixmap while efficiently maintaining the image resolution? Is scaled() the wrong way to go altogether? I could theoretically just reference the original file each time I zoom in and out and create a fresh pixmap at the desired scale, but that assumes that the files are always accessible (which they may not be in my case).
EDIT: Okay so based on comments I need to create a new pixmap copy for each scale cycle, now the question is how cleanest to do that and how do I make a new instance of the pixmap without editing the original? Here's a snippet of basically what I have now:
global pixArray
pixArray = []
# pix array
label = QtGui.QLabel()
pic = QtGui.QPixmap(imageFile)
label.setPixmap(pic)
#toss this label into the master array for later
pixArray.append(label)
# apply scaled image
label = pixArray[len(pixArray)-1]
picScaled = label.pixmap()
label.setPixmap(picScaled.scaled(rowWidth, rowHeight))
# so now the user wants to scale everything, rowWidth and rowHeight have changed:
for column in range(self.table.columnCount()):
# resize the cells
self.table.setColumnWidth(column, rowWidth)
self.table.setRowHeight(0, rowHeight)
# resize the pixmap label
item = self.table.cellWidget(0, column)
label = pixArray[column]
pic = label.pixmap()
# at this point I am actually scaling the original pixmap, how to create a copy?
item.setPixmap(pic.scaled(rowWidth, rowHeight))