PDA

View Full Version : QListView - To select a disabled item



agarny
9th July 2011, 19:57
Hi,

I have a form that contains a QListView which is populated with checkable items. Some of those items are disabled to make it visually clear to the user that they can't be checked/unchecked.

Now, I want to be able to provide the user with additional information about a particular item, be it enabled or not. If the item is enabled, it's simple, all I need to do is to handle the currentChanged signal of the selectionModel of my QListView object. This, however (and obviously?), doesn't work for disabled items.

So, how could I allow the user to 'select' a disabled item so that I can provide him with additional about that item?

Cheers, Alan.

Talei
9th July 2011, 20:13
Use delegate and then paint disabled check boxes (option.state in delegate paint() event - use additional information to determine if check boxes should be disabled/enabled ). That way internally those items are enabled but user sees them as disabled.

agarny
9th July 2011, 20:37
Ok, I have never used delegates, but it would seem worth checking out indeed. Thanks for the suggestion!

agarny
10th July 2011, 01:23
Ok, I have implemented or, at least, tried to implement a delegate solution (see https://github.com/opencor/opencor/blob/master/src/pluginswindow.cpp). It kind of works in that I get the behaviour I am after, but the drawing of the items (be they 'enabled' or 'disabled') doesn't look native (as is the case without the use of a delegate). For example, on Windows 7, without the delegate I get a 'transparent' blue while with the delegate I get an 'opaque' blue. So, I am close, but not quite there yet...

Added after 25 minutes:

Ok, I have just fixed the issue I mentioned above. Clearly still learning about (powerful) delegates... (https://github.com/opencor/opencor/commit/5334d6b3c6f150643d1ede14b3471bae41044e03)