Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QWidget * Q3Table::createEditor ( int  row,
int  col,
bool  initFromCell 
) const [protected, virtual]

This function returns the widget which should be used as an editor for the contents of the cell at row, col.

If initFromCell is true, the editor is used to edit the current contents of the cell (so the editor widget should be initialized with this content). If initFromCell is false, the content of the cell is replaced with the new content which the user entered into the widget created by this function.

The default functionality is as follows: if initFromCell is true or the cell has a Q3TableItem and the table item's Q3TableItem::isReplaceable() is false then the cell is asked to create an appropriate editor (using Q3TableItem::createEditor()). Otherwise a QLineEdit is used as the editor.

If you want to create your own editor for certain cells, implement a custom Q3TableItem subclass and reimplement Q3TableItem::createEditor().

If you are not using {Q3TableItem}s and you don't want to use a QLineEdit as the default editor, subclass Q3Table and reimplement this function with code like this:

    Q3TableItem *i = item(row, col);
    if (initFromCell || (i && !i->isReplaceable()))
        // If we had a Q3TableItem ask the base class to create the editor
        return Q3Table::createEditor(row, col, initFromCell);
    else
        return ...(create your own editor)
Ownership of the editor widget is transferred to the caller.

If you reimplement this function return 0 for read-only cells. You will need to reimplement setCellContentFromEditor() to retrieve the data the user entered.

See also:
Q3TableItem::createEditor()

Reimplemented in Q3DataTable.

Definition at line 5002 of file q3table.cpp.

References Q3TableItem::createEditor(), Q3TableItem::editType(), isColumnReadOnly(), Q3TableItem::isReplaceable(), isRowReadOnly(), item(), and Q3ScrollView::viewport().

Referenced by beginEdit().

{
    if (isReadOnly() || isRowReadOnly(row) || isColumnReadOnly(col))
        return 0;

    QWidget *e = 0;

    // the current item in the cell should be edited if possible
    Q3TableItem *i = item(row, col);
    if (initFromCell || (i && !i->isReplaceable())) {
        if (i) {
            if (i->editType() == Q3TableItem::Never)
                return 0;

            e = i->createEditor();
            if (!e)
                return 0;
        }
    }

    // no contents in the cell yet, so open the default editor
    if (!e) {
        e = new QLineEdit(viewport(), "qt_lineeditor");
        ((QLineEdit*)e)->setFrame(false);
    }

    return e;
}


Generated by  Doxygen 1.6.0   Back to index