Skip to content Skip to sidebar Skip to footer

How To Make Subclass Of Qstyleditemdelegate React Properly On Mouse Hover In A Qlistview In Pyside/pyqt?

On my way to solve the problems I stated in earlier questions (question 1, question 2) alone, I succeeded to implement a custom QStyledItemDelegate which meets my demands. Here is

Solution 1:

The value of option.state is the result of a bitwise or operation of many QStyle.state flags.

To see if you currently need to draw the mouseOver state, you just need to do:

ifoption.state&QStyle.State_MouseOver:# draw mouseover stuffelse:# don't draw mouse over stuff

There may be many other flags set, which you can choose to handle or not by writing similar if statements (all the flags are listed in the c++ documentation I linked to above).

I suspect this is why you are seeing inconsistent behaviour. You are only catching a couple of the mouseOver state flags and ignoring times when other (unrelated) style flags are also set. I suggest reading up about bitwise and-ing and or-ing to learn why flags are combined and extracted like this, and you you get results that are really large integers when you print it.

Finally, I suspect that the lower border is not changing colour because the next item below is drawing the border on top of it. This probably means you calculation for the size of the rectangle is wrong. I suggest doing some debugging along this lines to see if you can work out why.

Post a Comment for "How To Make Subclass Of Qstyleditemdelegate React Properly On Mouse Hover In A Qlistview In Pyside/pyqt?"