[PyKDE] unexpected extended selection behavior in QListView

Matthew Scott gmane at goldenspud.com
Mon Aug 9 23:11:00 BST 2004

Hello all,

The following code exhibits unexpected behavior using PyQt 3.12 and QT 
3.3.2 on Debian unstable.  It also exhibits the behavior when using PyQt 
3.11 and QT 3.3.1 as provided by the BlackAdder demo for Win32.

After running the code, the second and third items will be selected, and 
the current item is set to the second.

When you hold down Shift and click the fourth item, -all- of the items 
are selected, as if the 1st item was actually the current item (which it 
isn't in this case).

Does anyone know of a workaround to use along with setCurrentItem() in 
order to make extended selection work as expected?  (Where only items 2, 
3, and 4 would be selected according to the example above)

- Matthew

# ---8<   snip   8<--------

import sys
import qt

class App(qt.QApplication):

     def __init__(self):
         qt.QApplication.__init__(self, sys.argv)
         self.mainWindow = MainWindow()

class MainWindow(qt.QMainWindow):

     def __init__(self):
         listView = qt.QListView(self)
         item1 = qt.QListViewItem(listView, 'item1')
         item2 = qt.QListViewItem(listView, 'item2')
         item3 = qt.QListViewItem(listView, 'item3')
         item4 = qt.QListViewItem(listView, 'item4')
         listView.setSelected(item2, True)
         listView.setSelected(item3, True)
         print 'Current item is item2?', listView.currentItem() is item2
         print 'Now hold down shift and click item 4.'

if __name__ == '__main__':
     app = App()

# ---8<   snip   8<--------

More information about the PyQt mailing list