Results 1 to 3 of 3

Thread: Validating QTable's cell

  1. #1
    Join Date
    Sep 2008
    Location
    Chennai
    Posts
    36
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Validating QTable's cell

    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 ..
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2008
    Location
    Chennai
    Posts
    36
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question Re: Validating QTable's cell

    Quote Originally Posted by soumyadeep_pan View Post
    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 ..
    Can any body help me....thank in advance ....

  3. #3
    Join Date
    Sep 2008
    Location
    Chennai
    Posts
    36
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Talking Re: Validating QTable's cell

    Quote Originally Posted by soumyadeep_pan View Post
    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 ....

    Qt Code:
    1. /*** Float Table Item header file ****/
    2. class FloatTableItem : public QTableItem
    3. {
    4. public :
    5. FloatTableItem ( QTable * in_qTable, EditType in_Et, const QString & in_strText );
    6. virtual QWidget * createEditor () const ;
    7. void setContentFromEditor( QWidget *w );
    8. virtual int rtti() const;
    9. };
    10. /*** Float Table Item header file ****/
    11.  
    12.  
    13. /*** Float Table Item implementation .cpp file ****/
    14.  
    15. FloatTableItem::FloatTableItem ( QTable * in_qTable, EditType in_Et, const QString & in_strText ) : QTableItem (in_qTable, in_Et, in_strText)
    16. {
    17. return;
    18. }
    19.  
    20. QWidget* FloatTableItem::createEditor() const
    21. {
    22. QLineEdit* le_Temp = (QLineEdit *) (QTableItem::createEditor());
    23. le_Temp->setMaxLength(6);
    24.  
    25. if (le_Temp)
    26. {
    27. QRegExp rx( "[0-9]{0,3}[.]?[0-9]{0,2}");
    28. QValidator* validator = new QRegExpValidator( rx, le_Temp );
    29. le_Temp->setValidator(validator);
    30. }
    31. return le_Temp;
    32. }
    33.  
    34. void FloatTableItem::setContentFromEditor( QWidget *in_qWidget )
    35. {
    36. if ( in_qWidget->inherits( "QLineEdit" ) )
    37. setText( ( (QLineEdit*)in_qWidget )->text() );
    38. else
    39. QTableItem::setContentFromEditor( in_qWidget );
    40. }
    41.  
    42. int FloatTableItem::rtti() const
    43. {
    44. return 32355;
    45. }
    46. /*** Float Table Item implementation .cpp file ****/
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 20th January 2009 at 15:22. Reason: missing [code] tags

Similar Threads

  1. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  2. Word wrapping in a QTableWidget cell
    By jcooperddtd in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2007, 03:57

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.