Results 1 to 1 of 1

Thread: QTableView: Edit without editing ability

  1. #1
    Join Date
    Mar 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView: Edit without editing ability

    I have QTableView with QAbstractTableModel. Each second I download XML data from server and parse it and merge into QAbstractTableModel data. I have one column which can be edited by doubleclick - it is named "callsign".

    When user wants to add new row into table he open modal dialog, fill fields and submit it.

    My problem is following. After add dialog is closed I doblueclicking on "callsign" column. Edit control opens in cell but I can not enter any data in it! There is a sense that focus is missed on table. Is is missed in other form controls too. I push TAB but nothing happens.

    Have anybody this problem?

    This is code of my model:
    Qt Code:
    1. QVariant TxOrderModel::data(const QModelIndex &index, int role) const
    2. {
    3. if (role == Qt::DisplayRole) {
    4. return m_TableData.getCellValue(index.row(), index.column());
    5. }
    6. if (role == Qt::EditRole) {
    7. return m_TableData.getCellValue(index.row(), index.column());
    8. }
    9. if (role == Qt::BackgroundColorRole) {
    10. return TxOrder::getStatusColor(m_TableData.getCellValue(index.row(), QString("order_status")).toInt());
    11. }
    12. return QVariant();
    13. }
    14.  
    15. Qt::ItemFlags TxOrderModel::flags(const QModelIndex &index) const
    16. {
    17. Qt::ItemFlags flags = QAbstractTableModel::flags(index);
    18. QString columnName = m_TableData.getColumnName(index.column());
    19.  
    20. if (columnName == "driver_callsign") {
    21. flags |= Qt::ItemIsEditable;
    22. }
    23.  
    24. return flags;
    25. }
    26.  
    27. bool TxOrderModel::setData(const QModelIndex &index, const QVariant &value, int role)
    28. {
    29. if (role == Qt::EditRole) {
    30. QString columnName = m_TableData.getColumnName(index.column());
    31.  
    32. if (columnName == "driver_callsign") {
    33. QString primaryKey = m_TableData.getRowFieldValue(index.row(), m_TableData.getKeyField());
    34. QString callsign = value.toString();
    35. if (!callsign.isEmpty()) {
    36. m_Order.setDriverToOrderByCallsign(primaryKey, callsign);
    37. emit dataChanged(index, index);
    38. }
    39. }
    40. }
    41. return true;
    42. }
    To copy to clipboard, switch view to plain text mode 

    And this is how I open add dialog box:
    Qt Code:
    1. void MainWindow::buttonEditOrderClick()
    2. {
    3. DialogOrderEdit dialog;
    4. dialog.exec();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Dialog modal property is set to true.


    Added after 24 minutes:


    I have disabled all updates of data in table and comment code in model setData(). I found the way to reproduce this error:
    1. Open window with QTableView.
    2. Open modal dialog.
    3. Close dialog.
    4. Fast doubleclick to edit cell while dialog are closing.
    Last edited by nickla; 23rd March 2011 at 21:25.

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. QTableView how to do something on start/end editing
    By nickla in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2011, 08:26
  3. problems editing rows in a QTableView
    By cyrfer in forum Qt Programming
    Replies: 4
    Last Post: 6th January 2010, 08:34
  4. Problem with editing QTableView
    By TimoSan in forum Qt Programming
    Replies: 0
    Last Post: 23rd November 2009, 10:46
  5. QTableView, editing, validating input
    By jml in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 00:57

Tags for this Thread

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.