I have Qt application with splitter based view: on the left side is QListWidget containing files that can be selected; selected file's contents are displayed in an appropriate format on the right side of the splitter. This part works fine.
I now need to add compare functionality: if one item is selected in QListWidget then its contents are displayed on the right side; if another item is selected than I would like to display diff result instead. (Things are a bit more complicated than that because not all items can be diff’ed.)
What I would like to do is have a single selection capability intact but then also enable only CTRL + mouse click for second selection. I tried using QAbstractItemView::ExtendedSelection and then filtering out Shift and mouse drag but had no luck with that approach: while I could capture Shift key with keyPressEvent() I couldn't prevent selection (I hoped just dropping the event would suffice); as for drag I used mouseMoveEvent() hoping to drop event when state changes to DragSelectingState but that didn't work either.
I then considered sticking with single selection but opening context menu on right click on the second item -- while right click does emit itemSelectionChanged() signal, I haven't figured out yet what to do with this since I don't know which item was right-clicked.
Open to any other creative suggestions that do not involve adding additional UI elements – I can’t have any extra buttons, combo boxes etc.