简体   繁体   中英

How to force a pseudo-state in a widget

I have my custom widget where I defined my stylesheet like this:

QWidget#this { background-color: red; }
QWidget#this:hover { background-color: yellow; }

This works when I move the mouse over the widget but I don't have this behaviour when I'm dragging another widget over the first one.

I have captured the DragMove event but can't figure out to send something like mouseHover event ( MouseMove events doesn't seem to work).

Is this possible? Is there another way to use the stylesheet when I'm dragging another widget?

I faced the same problem a few days ago. Try to define a custom property for your widget, something like dragging , and use conditionals for your style sheet:

QWidget#this[dragging=true]{
    background-color: red;
}

Maybe you will need to use QStyle::polish() after changing the custom property, in order to refresh your widget style.

I hope this helps you.

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