views:

54

answers:

3

Hey everybody,

I'm wondering if there is a simple and quick way of displaying an image when the user hovers a QLabel...

Since QLabel can be used to display QPixmap, I would like to display some kind of "preview" when hovering a QLabel...

Do you guys know how I could manage this ?

Thanks in advance !

+2  A: 

You can set the tooltip to use html, including <img> tags. Will that do what you need?

As described in the docs, you can override the object's event handler if you need to do something fancier in a tooltip than can be done by default. (such as selecting a particular area of an image to put in the tooltip)

As long as you set the button size large enough, you should be able to capture the mouse-over events and display on mouse-over... but this seems like a somewhat strange way to go about things. Why not display all the images at first?

jkerian
MMmm I'm gonna try this ! Actually, in the form, I want a few images to be as small as possible... On the other hand, I want the user to be able to check those image in details by getting them lot bigger ! Actually, I just realized I want my application to behave a bit like the news "Images" tab of Google.com... Except my basic images will be smaller and the "tooltip" will be bigger :)
Andy M
Excellent result ! Thanks a lot mate !
Andy M
A: 

I don't know what kind of layout your QLabel is in, but I'm guessing it will cause weird layout changes if you just set the pixmap on the label when mouseovering it. Rather use a tooltip or just display a pixmap freely on the canvas.

teukkam
+1  A: 

For those who are interested in the result proposed by jkerian :

Simply :

MyLabel->setToolTip("<html><img src="+MyImagePathAsString+"/></html>");

Will result in :

alt text

Thanks again to jkerian.

Andy M