Results 1 to 4 of 4

Thread: QTableWidget::selectedItems()

  1. #1
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QTableWidget::selectedItems()

    I am using QTableWidget to create a table of mp3s and their ID3 tag information. I want to be able to handle multiple selections in the the table. It seems selectedItems() behaves differently based on how the items were selected. I have my table set to only select rows. When two contiguous rows are selected, item.at(0) is row 0 col 0 and item.at(1) is row 1 col 0. If the selected rows are not contiguous item.at(0) is row 0 col 0 and item.at(1) is row 0 col 1. I can I code it so that my functions work either way? Is there a better way to get the selected items? Or will using a mode/view combo solve my problem?

    Thanks
    mAx

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget::selectedItems()

    Better use QItemSelectionModel::selectedRows() (and then map those QModelIndexes to a QTableWidgetItem*).

    Apart from that: why not use the chance and roll your own model and use QTableView? (Believe me, it's worth the effort.)

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

    maxpower (27th January 2009)

  4. #3
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QTableWidget::selectedItems()

    Thanks. I used the QStandardItemModel with a QItemSelectionModel and it is working they way I expected. I am not sure of the benefit of creating a custom model. I looked at some other custom models and they made sense as to why you would create them (an items value was based on the value of other items and this was computed internally by the model). I just don't see how my model of mp3 tag info would benefit.

    Thanks
    mAx

  5. #4
    Join Date
    Apr 2011
    Location
    Poland
    Posts
    10
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget::selectedItems()

    What QTableWidget::selectedItems return if there isn't anything selected?


    EDIT:

    It hit me a couple moments after posting.... An empty list .
    Last edited by Olivia; 29th April 2011 at 15: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
  •  
Qt is a trademark of The Qt Company.