Results 1 to 3 of 3

Thread: Add new item to a QListView

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Add new item to a QListView

    Hi
    I have a QListView associated to a QStringListModel.
    Qt Code:
    1. void txtEdit::addChar()
    2. {
    3. QString testChar("x");
    4. int row = m_ui->usedList->currentIndex().row() + 1;
    5. usedListModel->insertRows(row, 1);
    6. QModelIndex index = usedListModel->index(row);
    7. m_ui->usedList->setCurrentIndex(index);
    8. m_ui->usedList->edit(index);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Line 8 allows me to type the content inside the QListView.
    Could't find a way to write testChar instead of editing the item!
    Where showld i look to find the solution for this?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Add new item to a QListView

    use QStringListModel::setData() for setting data to your model.

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

    graciano (18th August 2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add new item to a QListView

    Perfect!
    I was looking in the view and not in the model.
    THAAANKKSS

Similar Threads

  1. How to Modify QListView item height?
    By blackfox in forum Qt Programming
    Replies: 7
    Last Post: 16th May 2012, 11:38
  2. [solved]QListView dynamic item height
    By kernel_panic in forum Qt Programming
    Replies: 8
    Last Post: 17th March 2009, 14:05
  3. find item in QListView
    By AD in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 13:50
  4. QListView item alignment
    By innerhippy in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2008, 09:32
  5. how to move item up and down in QListView
    By zhanglr in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2008, 14:39

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.