PDA

View Full Version : Validating QTable's cell



soumyadeep_pan
7th January 2009, 09:51
I want to validate float values in a particular QTable's cell, so I created a custom table item a set it to the particular cell. I am able to get the line edit of the cell using the createEditor(), and able to validate the values. But When ever I have click that particular cell the previous existing values are reset to NULL, I want to keep the old values present in the cell. I have attached the sample code I have used, I also find out the problem in my code, the problem is I am creating new line edit object inside the createEditor() (tableitem.h), which is the problem. But if I do not create a new object how I can achieve my requirement for validating a cell. Please help me ..:crying:

soumyadeep_pan
8th January 2009, 10:58
I want to validate float values in a particular QTable's cell, so I created a custom table item a set it to the particular cell. I am able to get the line edit of the cell using the createEditor(), and able to validate the values. But When ever I have click that particular cell the previous existing values are reset to NULL, I want to keep the old values present in the cell. I have attached the sample code I have used, I also find out the problem in my code, the problem is I am creating new line edit object inside the createEditor() (tableitem.h), which is the problem. But if I do not create a new object how I can achieve my requirement for validating a cell. Please help me ..:crying:

Can any body help me....thank in advance ....

soumyadeep_pan
20th January 2009, 03:41
Can any body help me....thank in advance ....

I got the solution for the problem ... sorry for posting already solved problems.... here is my code for example, please post if any thing wrong ... thanks in advance ....:D


/*** Float Table Item header file ****/
class FloatTableItem : public QTableItem
{
public :
FloatTableItem ( QTable * in_qTable, EditType in_Et, const QString & in_strText );
virtual QWidget * createEditor () const ;
void setContentFromEditor( QWidget *w );
virtual int rtti() const;
};
/*** Float Table Item header file ****/


/*** Float Table Item implementation .cpp file ****/

FloatTableItem::FloatTableItem ( QTable * in_qTable, EditType in_Et, const QString & in_strText ) : QTableItem (in_qTable, in_Et, in_strText)
{
return;
}

QWidget* FloatTableItem::createEditor() const
{
QLineEdit* le_Temp = (QLineEdit *) (QTableItem::createEditor());
le_Temp->setMaxLength(6);

if (le_Temp)
{
QRegExp rx( "[0-9]{0,3}[.]?[0-9]{0,2}");
QValidator* validator = new QRegExpValidator( rx, le_Temp );
le_Temp->setValidator(validator);
}
return le_Temp;
}

void FloatTableItem::setContentFromEditor( QWidget *in_qWidget )
{
if ( in_qWidget->inherits( "QLineEdit" ) )
setText( ( (QLineEdit*)in_qWidget )->text() );
else
QTableItem::setContentFromEditor( in_qWidget );
}

int FloatTableItem::rtti() const
{
return 32355;
}
/*** Float Table Item implementation .cpp file ****/