// Set the mask to Price.
ui->leditPreco->setInputMask("000.009,99;_");
// Set validator to Price.
QRegExp preco
("^\\d{1,3}(([.]\\d{3})*),(\\d{2})$");
...
_model = new TSqlTableModel(this); _model->setTable("Produtos");
...
_model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("Price"));
...
ui->tviewProdutos->setModel(_model);
_mapper->addMapping(ui->leditCodigo, 0);
_mapper->addMapping(ui->leditDescr, 1);
_mapper->addMapping(ui->leditQtde, 2);
_mapper->addMapping(ui->leditPreco, 3);
// Populate the table and go to first record.
_model->select();
_mapper->toFirst();
connect( ui->tviewProdutos->selectionModel()
, _mapper
);
// Set the mask to Price.
ui->leditPreco->setInputMask("000.009,99;_");
// Set validator to Price.
QRegExp preco("^\\d{1,3}(([.]\\d{3})*),(\\d{2})$");
ui->leditPreco->setValidator(new QRegExpValidator(preco, ui->leditPreco));
ui->leditPreco->setLocale( QLocale(QLocale::Portuguese, QLocale::Brazil) );
...
_model = new TSqlTableModel(this); _model->setTable("Produtos");
_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
...
_model->setHeaderData(3, Qt::Horizontal, QObject::tr("Price"));
...
ui->tviewProdutos->setModel(_model);
_mapper = new QDataWidgetMapper(this); _mapper->setModel(_model);
_mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
_mapper->addMapping(ui->leditCodigo, 0);
_mapper->addMapping(ui->leditDescr, 1);
_mapper->addMapping(ui->leditQtde, 2);
_mapper->addMapping(ui->leditPreco, 3);
// Populate the table and go to first record.
_model->select();
_mapper->toFirst();
connect( ui->tviewProdutos->selectionModel()
, SIGNAL(currentRowChanged(QModelIndex,QModelIndex))
, _mapper
, SLOT(setCurrentModelIndex(QModelIndex))
);
To copy to clipboard, switch view to plain text mode
Bookmarks