2
votes

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?

1
Did you try QWidget::dragEnterEvent()?vahancho
Well, I have this behaviour implemented in Stylesheets so I wanted to solve it using the same method. With dragEnterEvent I can capture the event but can't change the stylesheet to the specified for the hover pseudo stateJavi Ortiz

1 Answers

3
votes

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.