Hi, On Tuesday 11 September 2012 15:20:33 Sensei wrote: > I need to display a QLabel that has an image and text in it, in > particular, a semi-transparent icon. All, without implementing another > custom widget. > > Googling, I found no ways of adding text and images, since one excludes > the other. Moreover, my images are black and transparent, used for some > QIcons I need, and I'd like to avoid creating another set of images, > just for the transparency. > > What I've done now is having two overlapping QLabels, one for the text, > the other for the icon. Now I just need to make the icon at a certain > alpha, but setWindowOpacity does not work on the QLabel containing the > pixmap. > > Any hints?
A few: Overlapping QLabels is not a good idea - you may get very weird effects next time anything changes in the implementation or next time you port to a new system. Create a pixmap and paint the icon and the text over it. Once you've done that for the first time it becomes very easy. Some untested code: //load the icon QPixmap pix("/my/iconfile.png"); //enable painting QPainter paint(&pix); //draw the text paint.begin(); paint.drawText(MY_X,MY_Y,"my text"); paint.end(); //create the label QLabel *mylabel=new QLabel(...); mylabel->setPixmap(pix); Konrad
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest