[SOLVED] How to get one selection out from 2 ListWidgets

Post here if you need help with creating a Graphical User Interface in Python.

[SOLVED] How to get one selection out from 2 ListWidgets

Postby salik89 » Mon Jan 27, 2014 8:42 am

Hi all, I have 2 QListWidgets and I am wondering if it is possible for user to select the items from the 2 lists.

Example, If user click and select and item in List A, there will not be any selection should the user click on an item in List B and vice verse.
Meaning to say no matter what, there cannot be 2 selections (one in each list)
salik89
 
Posts: 13
Joined: Mon Jan 20, 2014 4:36 pm

Re: How to get one selection out from 2 ListWidgets

Postby salik89 » Tue Jan 28, 2014 10:57 am

Found a solution... could the moderator kindly help me close this thread, thanks!
salik89
 
Posts: 13
Joined: Mon Jan 20, 2014 4:36 pm

Re: How to get one selection out from 2 ListWidgets

Postby stranac » Tue Jan 28, 2014 12:45 pm

You should post your solution.
It could help others with a similar problem.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm

Re: How to get one selection out from 2 ListWidgets

Postby salik89 » Tue Jan 28, 2014 1:04 pm

As requested, here is my working solution. Let me use an example.

Code: Select all
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)


Apparently this works for me. But if there are more working solutions, please do share with me and others! :D
salik89
 
Posts: 13
Joined: Mon Jan 20, 2014 4:36 pm


Return to GUI

Who is online

Users browsing this forum: Bing [Bot] and 2 guests