I had an app that created icons from QPixmaps, but I ran into performance issues because my source images were so much larger than the icons, so I ended up generating xpm icon files on the fly and it really sped things up.
On Friday, August 24, 2012 6:58:42 AM UTC+8, jdob wrote: > > You'll have to handle the cropping/scaling yourself. Fortunately QPixmap > makes this pretty easy - check out > QPixmap.copy()<http://doc-snapshot.qt-project.org/4.8/qpixmap.html#copy-2>and > QPixmap.scaled()<http://doc-snapshot.qt-project.org/4.8/qpixmap.html#scaled>. > > If I understand you correctly, you probably want to do something like this: > > > pixmap = QtGui.QPixmap('/path/to/image.png') > > # resize pixmap > pixmap = pixmap.scaled(button.size(), QtCore.Qt.KeepAspectRatioByExpanding, > QtCore.Qt::SmoothTransformation) > > # crop pixmap - the following assumes the image aspect is always wider > than the button. if that's not the case > # you'll need to compare your image/button aspects and crop > vertically/horizontally as necessary > cropOffsetX = (pixmap.width() - button.size().width()) / 2 > pixmap = pixmap.copy(cropOffsetX, 0, button.size().width(), > button.size().height()) > > button.setIcon(QtGui.QIcon(pixmap)) > > > > On Wednesday, August 22, 2012 9:07:09 PM UTC-7, Panupat wrote: >> >> Thanks jdob! >> >> Finally I got the thumbnails into my view by making them icons of >> QPushButton and lay them in their own widgets. >> >> Is there any flag to control how the image got resized into icon? Right >> now it retains it's aspect ratio, leaving some grey color where it doesn't >> cover. I actually want it to cover the whole icon area, cropping out what's >> beyond instead. Is there a way to do so? >> >> Best regard, >> Panupat. >> >> On Tue, Aug 21, 2012 at 12:13 AM, jdob <[email protected]> wrote: >> >>> The simplest way to do this is probably using QLabel(s) for text and >>> images and laying them out in a QGridLayout. You'll have to use 2 QLabels >>> if you want to display both an image and text (since QLabel shows an image >>> or text but not both). In that case, you'll need to place your image and >>> text inside a QVBoxLayout and then add that layout to the grid. Then you >>> can wrap the grid layout inside a QScrollArea. >>> >>> Another (more flexible) way to solve this is using Qt's Graphics View >>> framework <http://qt-project.org/doc/qt-4.8/graphicsview.html>. Take a >>> look at QGraphicsPixmapItem and QGraphicsSimpleTextItem >>> >>> >>> On Monday, August 20, 2012 3:54:08 AM UTC-7, Panupat wrote: >>>> >>>> If I have a list of full path + image file names, how do I populate >>>> them as square thumbnails with text label into scrollable area? What class >>>> should I look at? Should I use QScrollArea for the wrapper? Something >>>> similar to sunday pipeline's >>>> http://www.3dg.dk/2011/08/12/**sunday-pipeline-maya-public/<http://www.3dg.dk/2011/08/12/sunday-pipeline-maya-public/> >>>> >>>> Thanks! >>>> >>> -- >>> view archives: http://groups.google.com/group/python_inside_maya >>> change your subscription settings: >>> http://groups.google.com/group/python_inside_maya/subscribe >>> >> >> -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
