PDA

View Full Version : Validator for the table widget item in table



mukunda
31st May 2011, 05:29
Hi,

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

mukunda

Santosh Reddy
31st May 2011, 06:22
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
QTableWidget::setCellWidget()

ChrisW67
31st May 2011, 08:03
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.

mukunda
6th June 2011, 11:51
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?

ChrisW67
6th June 2011, 23:07
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.