Results 1 to 1 of 1

Thread: Problem with storing data of QTableView to QSatndardItemModel which has delegate

  1. #1
    Join Date
    Sep 2011
    Posts
    24
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with storing data of QTableView to QSatndardItemModel which has delegate

    Hi,

    I'm using a QTableView to present data of QStandardItemModel. I'm using a combobox delegate for the second column. I want to store data in my custom data structure too. However when I catch the itemChanged(QStandardItem*) signal I don't get the current value of the cell (data = "", which is not in the column 1). But the data entered in these columns remains even the selected cell changed. So they are stored in the model. When I do a run time debug I found that setModelData only emitted if the combobox changed. In normal cell editing this signal is not emitting.

    Here's the code fragment to clear up.

    Qt Code:
    1. //Model
    2. p_TableFields = new QStandardItemModel(this);
    3. p_TableFields->insertColumns(0, 4);
    4. p_TableFields->insertRows(0, 3);
    5.  
    6. //Table View
    7. tblFields->setModel(p_TableFields);
    8.  
    9. //ComboBox delegation for column 1
    10. p_delegate = new DelegateComboBox(tblFields);
    11. tblFields->setItemDelegateForColumn(1, p_delegate);
    12.  
    13. //Signal for data change
    14. connect(p_TableFields, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(CellEdited(QStandardItem*)));
    15.  
    16. //Cell Edited function
    17. QString value = item->data().toString(); //this is ""(empty)
    18.  
    19.  
    20. //Custom delegation - Only fired for column 1
    21. setModelData( QWidget *editor, QAbstractItemModel *model,
    22. const QModelIndex &index ) const
    23. {
    24. if ( index.column() == 1 )
    25. {
    26. QComboBox *comboBox = static_cast<QComboBox*>(editor);
    27. QString str = comboBox->currentText();
    28.  
    29. if ( str.compare("<select>") )
    30. model->setData(index, str);
    31.  
    32. return;
    33. }
    34.  
    35. QItemDelegate::setModelData(editor, model, index);
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by IndikaU; 4th October 2011 at 06:57.

Similar Threads

  1. Storing the program data in a "safe place"
    By kremuwa in forum Qt Programming
    Replies: 9
    Last Post: 5th August 2010, 10:23
  2. Replies: 10
    Last Post: 20th June 2010, 22:29
  3. Saving and storing data,QtSql
    By salmanmanekia in forum Newbie
    Replies: 7
    Last Post: 20th April 2010, 19:08
  4. storing data in hexadecimal format
    By aj2903 in forum Qt Programming
    Replies: 6
    Last Post: 13th January 2010, 05:29
  5. Replies: 1
    Last Post: 3rd December 2009, 09:20

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.