PDA

View Full Version : QItemDelegate problem



WinchellChung
4th December 2007, 23:57
I have a QWidget that displays a series of image thumbnails. The thumbnails appear as image boxes in a grid pattern.

The thumbnails are drawn by a custom QItemDelegate. It draws a box and an image. Now, according to the customer's spec, when the cursor is moved over a thumbnail, a little "X" delete button has to appear on that specific thumbnail. So the itemDelegate's paint() method checks the QStyleOptionViewItem argument, checking for QStyle::State_MouseOver. If that flag is there, it draws the "X" delete button.

That is working perfectly.

Here is the problem.

Say you have a row of thumbnails A, B, C, D and E. You move the cursor over C. The X delete button appears. You click the delete button. Thumbnail C vanishes.

Now, the remaining thumbnails move over to close the gap, so you have A, B, D, and E. The cursor has not move, but it is now over thumbnail D.

The bug is, the X delete button does NOT appear, since the mouse has not moved. True, it appears the instant the mouse is moved, but the customer is not pleased.

I am unsure as to the best way of dealing with this. I tried doing a reset() on the model, but of course that did nothing. That won't set the QStyle::State_MouseOver on the appropriate itemDelegate.

Any suggestions?

wysota
5th December 2007, 00:15
The problem is not with the delegate. If you want, you might post the event to the view yourself.

WinchellChung
5th December 2007, 17:16
Thanks, wysota. Boy do I feel stupid.