Results 1 to 5 of 5

Thread: Validator for the table widget item in table

  1. #1
    Join Date
    Jan 2011
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Validator for the table widget item in table

    Hi,

    Can i keep validator for the QTableWidgetItem as we can assign validator for the line edit.

    mukunda

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Validator for the table widget item in table

    You have to use a QLineEdit and put it over the QTableWidgetItem, (i.e. put the widget on the cell where you have your QTableWidgetItem) this can be done using
    Qt Code:
    1. QTableWidget::setCellWidget()
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Validator for the table widget item in table

    Look at QStyledItemDelegate::createEditor() and QTableView::setItemDelegate() (and the related row/column versions). You can provide a custom editor, when required, for particular columns, rows, or the whole table and attach any validator you like.

  4. #4
    Join Date
    Jan 2011
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Validator for the table widget item in table

    I dont want to set the cell widget with line edits and set the validators to the lineedits.
    Is there any direct way of setting the validators to the table widget items?

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Validator for the table widget item in table

    Read my last post. Using the delegate mechanism you create an editor widget only when editing is actually attempted. There is only the one QLineEdit with its validator. That widget goes away when the editing is finished.
    Last edited by ChrisW67; 6th June 2011 at 23:25.

Similar Threads

  1. Edit table for my own table-widget
    By MasterMatrix in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2010, 07:05
  2. Getting an item from an empty table widget
    By ProTonS in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 02:24
  3. How to refresh table item
    By vieraci in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2009, 00:43
  4. Qt4 Table Item Spanning
    By billyp in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2008, 17:11
  5. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 09:56

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.