简体   繁体   中英

Qt draw small 'x' icon on custom-rendered control

I'm drawing a custom control in Qt in the paintEvent function (so I have a QPainter to do the drawing). Now I'd like to add a small close 'x' icon that animates when the mouse is over it.

I know that QPainterPath has a " contains " method that I can use to test mouse entering the area, but I'm wondering how should I go to draw the small 'x'.

I'd like the 'x' to animate around (eg to spin) when the mouse enters the area, but I'm not sure how to accomplish this. I've tried manually drawing my 'x' but it feels overly complicated.. furthermore rotating it would be a pain.

What's the best way to draw a small icon in a custom-rendered control (preferably in a QPainterPath) ?

I would add an Icon to the app then draw the pixmap of that QIcon. If there is a function to draw a pixmap with rotation you can use QPropertyAnimation to "animate" the rotation angle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM