QString searchValue
= ui
->lineEdit_search_clients
->text
();
proxyModel->setSourceModel(model);
proxyModel
->setFilterRegExp
(QRegExp(searchValue, Qt
::CaseInsensitive,
QRegExp::FixedString));
connect(ui
->lineEdit_search_clients,
SIGNAL(textChanged
(QString)),
proxyModel,
SLOT(setFilterFixedString
(QString)));
model->setQuery("SELECT ROWID, ClientName, ClientCity, ClientEik FROM clients");
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("RowID"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Name"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("City"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("ID"));
ui->tableView_clients->setModel(proxyModel);
ui->tableView_clients->setSortingEnabled(true);
ui->tableView_clients->setColumnWidth(0,30);
ui->tableView_clients->setColumnWidth(1,170);
ui->tableView_clients->setColumnWidth(2,100);
ui->tableView_clients->setColumnWidth(3,70);
ui
->tableView_clients
->horizontalHeader
()->setResizeMode
(QHeaderView::Interactive);
ui->tableView_clients->horizontalHeader()->setStretchLastSection(true);
ui->tableView_clients->show();
QString searchValue = ui->lineEdit_search_clients->text();
QSqlQueryModel *model=new QSqlQueryModel(this);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(model);
proxyModel->setFilterRegExp(QRegExp(searchValue, Qt::CaseInsensitive, QRegExp::FixedString));
connect(ui->lineEdit_search_clients, SIGNAL(textChanged(QString)),
proxyModel, SLOT(setFilterFixedString(QString)));
model->setQuery("SELECT ROWID, ClientName, ClientCity, ClientEik FROM clients");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("RowID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("City"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("ID"));
ui->tableView_clients->setModel(proxyModel);
ui->tableView_clients->setSortingEnabled(true);
ui->tableView_clients->setColumnWidth(0,30);
ui->tableView_clients->setColumnWidth(1,170);
ui->tableView_clients->setColumnWidth(2,100);
ui->tableView_clients->setColumnWidth(3,70);
ui->tableView_clients->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
ui->tableView_clients->horizontalHeader()->setStretchLastSection(true);
ui->tableView_clients->show();
To copy to clipboard, switch view to plain text mode
Bookmarks