PDA

View Full Version : QTableView: Edit without editing ability



nickla
23rd March 2011, 22:25
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:


QVariant TxOrderModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole) {
return m_TableData.getCellValue(index.row(), index.column());
}
if (role == Qt::EditRole) {
return m_TableData.getCellValue(index.row(), index.column());
}
if (role == Qt::BackgroundColorRole) {
return TxOrder::getStatusColor(m_TableData.getCellValue(i ndex.row(), QString("order_status")).toInt());
}
return QVariant();
}

Qt::ItemFlags TxOrderModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
QString columnName = m_TableData.getColumnName(index.column());

if (columnName == "driver_callsign") {
flags |= Qt::ItemIsEditable;
}

return flags;
}

bool TxOrderModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role == Qt::EditRole) {
QString columnName = m_TableData.getColumnName(index.column());

if (columnName == "driver_callsign") {
QString primaryKey = m_TableData.getRowFieldValue(index.row(), m_TableData.getKeyField());
QString callsign = value.toString();
if (!callsign.isEmpty()) {
m_Order.setDriverToOrderByCallsign(primaryKey, callsign);
emit dataChanged(index, index);
}
}
}
return true;
}


And this is how I open add dialog box:


void MainWindow::buttonEditOrderClick()
{
DialogOrderEdit dialog;
dialog.exec();
}


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.