Results 1 to 8 of 8

Thread: QListWidget muti-selection problem

  1. #1
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    5
    Qt products
    Platforms
    MacOS X Windows

    Default QListWidget muti-selection problem

    Hi Everybody.

    Need help with a problem.

    I have implemented a QListWidget and populated it with some entries. Now I want the following functionality.

    1. When I click on a single item, a Single Click event should be execute. Using "itemClicked" and is working fine.
    2. For double click, I am using "itemDoubleClicked"

    The problem is how to select multiple items and then trigger a signal? I tried "itemSelectionChanged" but whenever I select an item to include it to my selection, Single Click event is triggered and I dont want that.

    If I select 5 items, then 5 Single Click events are getting triggered.

    I am using Python 2.7.3, 64 bit with Qt 4.7
    Any help would be appreciated.

    Mohsin

  2. #2
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListWidget muti-selection problem

    Could you elaborate why you need to choose multiple items from the QListWidget?

  3. The following user says thank you to Gokulnathvc for this useful post:

    mohsin7998 (26th October 2012)

  4. #3
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    5
    Qt products
    Platforms
    MacOS X Windows

    Default Re: QListWidget muti-selection problem

    Thanks for the reply Gokulnathvc.

    I am making a list of movies using QListWidget. What I want to do is that, when I single click an item, in the list, my call back function should display the properties of that item. And when I select multiple item by using mouse or keyboard, another event should get triggered and it should return me all the selected items. I am still using the single click function for it and then deciding on the number of items selected to make the decision. Using the following code:

    def single_click_function (self, event):
    items = self.unsubmittedList.selectedItems() #unsubmittedList is QListWidget
    # items = self.unsubmittedList.GetItems()
    # selected = self.unsubmittedList.GetSelections()
    if self.WIN_32:
    if len(selected) == 1: #If I select 1 item
    version = items[selected[0]]
    for ver in self.unsubmitted_versions:
    if version == ver["code"]:
    time = datetime.fromtimestamp(mktime(ver["created_at"].timetuple()))
    self.rangeText.SetLabel(ver["frame_range"])
    self.descText.SetLabel(str(ver["description"]))
    self.shotRangeText.SetLabel(ver["render_range"])
    self.createdText.SetLabel(time.strftime("%d/%m/%Y %H:%M"))
    else: #If more than one item
    self.rangeText.SetLabel("")
    self.descText.SetLabel("")
    self.shotRangeText.SetLabel("")
    self.createdText.SetLabel("")

    path = '"'
    for ver1 in self.unsubmitted_versions: #unsubmitted_versions contains my movies.
    for item in selected:
    if ver1["code"] == items[item]:
    path += ver1["sg_uploaded_movie"]["local_path_windows"] + '" "'

    path = path[:-2]
    path_win = path

    if self.qt_process:
    try:
    self.qt_process.terminate()
    except:
    pass

    if path:
    cmd = self.player + ' ' + path_win
    self.qt_process = Popen(shlex.split(cmd))
    else:
    self.rangeText.SetLabel("")
    self.descText.SetLabel("")
    self.shotRangeText.SetLabel("")
    self.createdText.SetLabel("")


    This code was working fine on wx but now I am using Qt and dont know why it is not working now.

    Any help would be appreciated.


    Cheers

  5. #4
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListWidget muti-selection problem

    Better use another QListWidget to list the selected list of entries from the List Widget. That could be better. Just populate the second ListWidget with the list of items selected from the first ListWidget.

  6. The following user says thank you to Gokulnathvc for this useful post:

    mohsin7998 (26th October 2012)

  7. #5
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QListWidget muti-selection problem

    This is perhaps possible to implement a signal which is emitted when a selected item is clicked. Then connect that signal to the slot you want. Probably by connection the QListWidget::itemClicked to a slot which checks whether the item was selected before clicking (a click should toggle the selection state).

  8. The following user says thank you to Ashkan_s for this useful post:

    mohsin7998 (26th October 2012)

  9. #6
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    5
    Qt products
    Platforms
    MacOS X Windows

    Default Re: QListWidget muti-selection problem

    I am looking into mouseReleaseEvent now and I think it would be a good idea.

    But it is not working in my QlistWidget, it only triggers an event when clicked on the main window.

    Need to override it in my QlistWidget but dont know how to.

    Any help would be appreciated.

    Cheers

  10. #7
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListWidget muti-selection problem


  11. The following user says thank you to Gokulnathvc for this useful post:

    mohsin7998 (29th October 2012)

  12. #8
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    5
    Qt products
    Platforms
    MacOS X Windows

    Default Re: QListWidget muti-selection problem

    Thanks mate.

    I am using python and the link is a bit confusing.

    I tried to apply the same logic using python but its not working.

    The mouse release event is working outside the List (On the main Widget) but not in the list where i want it to.

    Hope u understand my problem.

    I have been told to override the mouse release event but that one too i snot working.

    Many thanks,
    Mohsin

Similar Threads

  1. QListWidget's selection issues
    By mirni in forum Qwt
    Replies: 0
    Last Post: 5th November 2009, 21:08
  2. QListWidget selection custom painting problem
    By xeento in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2008, 10:49
  3. Item Selection in QListWidget
    By mclark in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2008, 16:53
  4. QTreeWidget & QListWidget different selection
    By munna in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2006, 07:50
  5. QListWidget selection behavior
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2006, 15:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.