Results 1 to 2 of 2

Thread: QListWidget: how to get current Item (which was set programatically)

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QListWidget: how to get current Item (which was set programatically)

    Hi,
    I have a dialong that when pupping up,it will populate some lists by loading data from a file.
    I have a Label, in which some selected items from the lists are shown.
    The problem is, that when the dialog loads, all selections are done programmatically - with no user input, and everything I tried in order to read the current items from the list doesn't work.
    The label will update only after I click or use keyboard on the lists.
    Here is what I tried:
    Setting the current item with:
    setCurrentItem();
    satCurrentRow();
    setCurrentIndex(); -> which actually should work if one follows the docs since:
    void QAbstractItemView::setCurrentIndex ( const QModelIndex & index ) [slot]

    Sets the current item to be the item at index. Depending on the current selection mode, the item may also be selected. Note that this function also updates the starting position for any new selections the user performs.

    To set an item as the current item without selecting it, call
    So I would expect, that myList->currentItem() will retrieve that item.
    But it doesn't.
    Is there a way to select an item in a QListWIdget programmatically?
    It must be possible - doesn't it?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget: how to get current Item (which was set programatically)

    I feagured it out.
    My Bad.
    The selection of the item occurs while the widget is not visible, and I show the slection only in case the widget was visible...

    Thanks.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Showing Pixmap as a QListWidget Item
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 1st February 2007, 13:25
  2. Replies: 3
    Last Post: 7th November 2006, 09:35
  3. Reg - add item in QListWidget
    By suresh in forum Newbie
    Replies: 1
    Last Post: 1st September 2006, 18:52
  4. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 20:41
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 10:56

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.