PDA

View Full Version : [Qt-3] QTable question



a550ee
28th September 2006, 08:48
Hello!
I need to find some special way to provide cell editors for table.
Instantiating editor each time QTable::createEditor() is called is not
suitable because it takes sufficient amount of time.
I've looked through examples and there is a solution (ex. bigtable) to
avoid multiple editor instantiation for each cell.
I want avoid multiple instantiation for each column! I mean all cells
in the same column should use one instance of editor.

I've played around overriding theese methods but didn't find
particular solution. Either widgets don't disappear when i finish
editing either they start blinking in all cells of a column.

QIntDict<QWidget> widgets;

QWidget * QtsDataTable::createEditor ( int row, int col, bool
initFromCell ) const
{
QWidget * w = widgets.find(col);
if( w == 0)
{
/*here goes widget instantiation and inserting it into widgets dict*/
}
return w;
}

void QtsDataTable::insertWidget( int r, int c, QWidget *w )
{
}

QWidget * QtsDataTable::cellWidget( int r, int c ) const
{
return 0;
}

void QtsDataTable::clearCellWidget( int r, int c )
{
}

wysota
28th September 2006, 08:55
I think you need to reimplement endEdit() too,

a550ee
28th September 2006, 12:03
Hello!
Thanks to you I make it work. In fact, I get rid of all overrides (createCellWidget, insertWidget, etc. ) except for beginEdit() and endEdit(). I don't know how good this solution is, but, as I mentioned before, it works.
To ensure I didn't forget anything, I'll provide code for beginEnd() and endEdit() here.



QWidget * QtsDataTable::beginEdit ( int row, int col, bool replace )
{
ensureCellVisible( row, col );
QWidget * w = 0;
/*here goes instantiating, setting values, etc.*/
if(w != 0)
{
w->installEventFilter ( this );
QRect cr = cellGeometry( row, col );
w->resize( cr.size() );
moveChild( w, cr.x(), cr.y() );
w->setActiveWindow();
w->show();
w->setFocus();
}
updateCell( row , col );
}




void QtsDataTable::endEdit ( int row, int col, bool accept, bool replace )
{
QWidget * w = 0;
/*here goes setting values, etc.*/
if(w != 0)
{
w->hide();
w->removeEventFilter( this );
}
setEditMode( QTable::NotEditing, -1, -1);
viewport()->setFocus();
updateCell( row, col);
}