Results 1 to 2 of 2

Thread: QTableView, editing, validating input

  1. #1
    Join Date
    Dec 2006
    Posts
    33
    Thanks
    10
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question QTableView, editing, validating input

    I'm using Qt4.2.3, and have created a custom model from QAbstractTableModel, using QTableView (for now). I want to be able to validate the input, and not let the user move to the next field if the input is invalid, and to give an error message in a text window. I set up an item delegate using QLineEdit as the editor, using a QValidator. The trouble is, this simply prevents the data from being stored in the model - the cursor still goes to the next field upon pressing TAB.

    I found a post about using the QWidget::eventFilter function, and started writing code to handle the event of type LeaveEditFocus. But, the compiler (VS) says it is undefined! I can only guess it's because it's conditionally compiled conditioned on QT_KEYPAD_NAVIGATION being defined. Does anyone know why that wouldn't be defined. Is there a better solution to what I am trying to do?

    Thanks for any help.

    Jim L.
    Seattle, WA

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableView, editing, validating input

    There is a flags() function in your model. Reimplement that to turn off Qt::ItemIsEditable for those cells you don't want edited. I suppose that function could check if all previous cells have been validated or not.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

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.