python 3.x - PyQt Keeping QLabel Size Aspect Ratio -
i have qlabel displays image. currently, have image set keep it's aspect ratio, , grow big can within qlabel.
is there way can set qlabel maintain image's aspect ratio? not want have "blank" qlabel space either side of image when label wider image.
i have been looking sort of qlabel property allow me set aspect ratio of label, have not managed wanted do.
all answers have seen relate keeping aspect ratio of resized qpixmap image, not of qlabel containing it.
any great!
cheers
fp
i seem have cracked it, incase else wondering how this:
i took tmoreau's solution , modified slightly. work, need set qlabel's maximum size image's new size prior paint event. afterwards, need set maximum size qlabel large, otherwise, not able enlarge image @ have specified maximum size of current image.
def paintevent(self, event): size = self.size() painter = qtgui.qpainter(self) point = qtcore.qpoint(0,0) scaledpix = self.pixmap.scaled(size, qt.keepaspectratio, transformmode = qt.smoothtransformation) self.setmaximumsize(scaledpix.size()) point.setx(0) point.sety(0) #print (point.x(), ' ', point.y()) painter.drawpixmap(point, scaledpix) self.setmaximumsize(qtcore.qsize(4000,5000)) if has better solution, means please let me know!
Comments
Post a Comment