How To Make Subclass Of Qstyleditemdelegate React Properly On Mouse Hover In A Qlistview In Pyside/pyqt?
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?"