Hi, I've been researching how to replace an image with another image when hovering over a widget, but I can't seem to figure it out (following the QStyle example) Does anyone have any pointers? A QPushButton is what I'm working with. Thanks!
Hi, I've been researching how to replace an image with another image when hovering over a widget, but I can't seem to figure it out (following the QStyle example) Does anyone have any pointers? A QPushButton is what I'm working with. Thanks!
see QPushButton::enterEvent() and QPushButton::leaveEvent().
Override them and on enter even set a QPixmap member in your QPushButton subclass to the image you want to paint.
On leave event you have to revert to the old image.
In paintEvent just paint the member QPixmap.
Or activate hover events for your widget by setting an appropriate attribute and then reimplement paintEvent, check there whether the cursor is currently hovering over the widget and act accordingly.
Thanks a lot for the suggestions! I'll see if I can get it working.
Thanks a lot for the suggestions! I'll see if I can get it working.
EDIT: ok, after fooling with the enter/leave events for a little while I came up with this, which works, but I wanted to see if you guys found anything wrong with it...
Qt Code:
{ logout->setIcon(*logout_hover); } { logout->setIcon(*logout_default); }To copy to clipboard, switch view to plain text mode
...where "logout" is my own QPushButton class.
I guess that's OK, but if you have higher quality/bigger resolution pictures then you'll hsvr yo paint them in paint event.
I don't see a point in using a pointer to a pixmap. Pixmaps are implicitly shared, so using a pointer yields no advantage.
Bookmarks