
Originally Posted by
anda_skoa
QListWidget has a signal called itemSelectionChanged().
Create two slots, one that is connected to the first list's signal and one that is connected to the second list's signal.
When the slots are invoked, they clear the other list's selection.
Since clearing the selection might also result in the signal being emitted, you need to take care of that, e.g. by setting a flag and ignoring the slot invokation while it is set. In both slots obviously.
Cheers,
_
Okay I will try out your method and see how it goes...
Nonetheless, I currently have a code below, it seems to be working for me, but could I get any advices if it is good enough?
from PyQt4.QtGui import *
widget.setLayout(l)
list01.addItems(["1","2","3"])
list02.addItems(["4","5","6"])
def test01():
list02.itemSelectionChanged.disconnect(test02)
for item in list02.selectedItems():
list02.setItemSelected(item,False)
list02.itemSelectionChanged.connect(test02)
def test02():
list01.itemSelectionChanged.disconnect(test01)
for item in list01.selectedItems():
list01.setItemSelected(item,False)
list01.itemSelectionChanged.connect(test01)
print dir(list01.itemSelectionChanged)
list01.itemSelectionChanged.connect(test01)
list02.itemSelectionChanged.connect(test02)
from PyQt4.QtGui import *
app = QApplication([])
widget = QWidget()
mainLayout = QHBoxLayout(widget)
widget.setLayout(l)
list01 = QListWidget()
list02 = QListWidget()
list01.addItems(["1","2","3"])
list02.addItems(["4","5","6"])
def test01():
list02.itemSelectionChanged.disconnect(test02)
for item in list02.selectedItems():
list02.setItemSelected(item,False)
list02.itemSelectionChanged.connect(test02)
def test02():
list01.itemSelectionChanged.disconnect(test01)
for item in list01.selectedItems():
list01.setItemSelected(item,False)
list01.itemSelectionChanged.connect(test01)
print dir(list01.itemSelectionChanged)
list01.itemSelectionChanged.connect(test01)
list02.itemSelectionChanged.connect(test02)
To copy to clipboard, switch view to plain text mode
Bookmarks