Results 1 to 3 of 3

Thread: can't qry QlistWidgetItem after changing selectionMode

  1. #1
    Join Date
    Jul 2015
    Posts
    8
    Qt products
    Platforms
    Windows

    Default can't qry QlistWidgetItem after changing selectionMode

    Hey guys, I'm doing PySide, I hope that's not a problem for this forum? Since it's very close to PyQt I will try.

    first I disconnect the previous function associated with the QListWidget click command
    I'm chaging the selection mode for my QListWidget and calling a new function on click
    (first question, do I also need to disconnect the old selection mode that was assigned or is setSelectionMode overriding the old one?)
    Qt Code:
    1. self.listWidget_lights.itemClicked.disconnect(self.funcUpdateLights)
    2. self.listWidget_filters.setSelectionMode (QtGui.QAbstractItemView.MultiSelection)
    3. self.listWidget_filters.itemClicked.connect(self.connectingFiltersFunc)
    To copy to clipboard, switch view to plain text mode 


    then I call:

    Qt Code:
    1. def connectingFiltersFunc(self):
    2. item = QtGui.QListWidgetItem(self.listWidget_filters)
    3. print item
    4. print self.listWidget_filters.indexFromItem(item).row()
    To copy to clipboard, switch view to plain text mode 

    and this is already behaving weird.
    If I click on one of my items in the widget multiple times to select or deselect it needs two clicks to select or deselect.
    Now even when I click the same item I always get a different result as pointer.
    print item returns when the same item is clicked:
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D348>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D988>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D808>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D4C8>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61DC88>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D788>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61DC48>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D708>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61DD88>
    <PySide.QtGui.QListWidgetItem object at 0x000000009B61D5C8>


    self.listWidget_filters.indexFromItem(item).row()
    this one looks in a dictionary to find the right entry and return what entry was just selected.
    this returns no matter what Item I select or deselect:

    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    .
    .
    .


    anyone any idea what's going on?
    I really just started with Pyside /qt

    thank you

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: can't qry QlistWidgetItem after changing selectionMode

    I do not know PySide, but doesn't this line
    Qt Code:
    1. item = QtGui.QListWidgetItem(self.listWidget_filters)
    To copy to clipboard, switch view to plain text mode 
    allocate and insert a new item in the listWidget_filters list? This would explain why, every time you click on some item in the list, item has a fresh address and its row number has been incremented.

    The item that was clicked is passed as a parameter to the QListWidget::itemClicked() signal. I do not know how it maps to PySide, but maybe all you have to do is to append a parameter to connectingFiltersFunc.

    Alternatively, since you use multiselection, you could call QListWidget::selectionModel() to get the selection model, and connect to its selectionChanged() signal to monitor changes in the set of selected items.

    As for you first question, I do not understand what you mean by "disconnect the old selection mode that was assigned", but all you have to do to change the selection mode is call setSelectionMode, which you do correctly.

  3. #3
    Join Date
    Jul 2015
    Posts
    8
    Qt products
    Platforms
    Windows

    Default Re: can't qry QlistWidgetItem after changing selectionMode

    you are right! I was beeing stupid, sorry for that, I forgot that I can just pass item along to the new function and just print it from there.
    Everything working now!

Similar Threads

  1. QSlider: changing the groove without changing the handle
    By Olivier Berten in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2013, 11:02
  2. Replies: 0
    Last Post: 14th September 2011, 14:30
  3. Replies: 2
    Last Post: 10th August 2009, 10:45
  4. Calendar widget with selectionMode != SingleSelection
    By Tamara in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2007, 11:13
  5. about QListWidgetItem
    By Pang in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2007, 10:14

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.