connect(ui->tableView_clients->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this, SLOT(setBool()));
To copy to clipboard, switch view to plain text mode
i use selectionChange() to check in setBool() wether to make buttons disabled or enabled. Generally it works, but when i add or edit record i run the following function in order to update the table:
//UPDATE MAIN TABLEVIEW
void Clients::updateClientTable()
{
QString searchValue
= ui
->lineEdit_search_clients
->text
();
proxyModel->setSourceModel(model);
proxyModel
->setFilterRegExp
(QRegExp(searchValue, Qt
::CaseInsensitive,
QRegExp::FixedString));
proxyModel->setFilterKeyColumn(-1);
connect(ui
->lineEdit_search_clients,
SIGNAL(textChanged
(QString)),
proxyModel,
SLOT(setFilterFixedString
(QString)));
connect(proxyModel, SIGNAL(hasSelection()),
ui->lineEdit_search_clients, SLOT(setText()));
model->setQuery("SELECT id, ClientName,ClientCity, ClientAddress, ClientMol, ClientEik, ClientVat, ClientTel, ClientMail FROM clients");
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("id"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Name"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("City"));
model
->setHeaderData
(5, Qt
::Horizontal,
QObject::tr("EIK"));
ui->tableView_clients->setModel(proxyModel);
//ui->tableView_clients->setSortingEnabled(true);
ui->tableView_clients->setColumnWidth(0,20);//ID
ui->tableView_clients->setColumnWidth(1,173);//ClientName
ui->tableView_clients->setColumnWidth(2,110);//ClientCity
ui->tableView_clients->setColumnWidth(3,0);//ClientAddress
ui->tableView_clients->setColumnWidth(4,0);//ClientMol
ui->tableView_clients->setColumnWidth(5,100);//ClientEik
ui->tableView_clients->setColumnWidth(6,0);//ClientVat
ui->tableView_clients->setColumnWidth(7,0);//ClientTel
ui->tableView_clients->setColumnWidth(8,0);//ClientMail
ui
->tableView_clients
->horizontalHeader
()->setResizeMode
(QHeaderView::Interactive);
ui->tableView_clients->horizontalHeader()->setStretchLastSection(true);
ui->tableView_clients->show();
//UPDATE MAIN TABLEVIEW
void Clients::updateClientTable()
{
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));
proxyModel->setFilterKeyColumn(-1);
connect(ui->lineEdit_search_clients, SIGNAL(textChanged(QString)),
proxyModel, SLOT(setFilterFixedString(QString)));
connect(proxyModel, SIGNAL(hasSelection()),
ui->lineEdit_search_clients, SLOT(setText()));
model->setQuery("SELECT id, ClientName,ClientCity, ClientAddress, ClientMol, ClientEik, ClientVat, ClientTel, ClientMail FROM clients");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("City"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("EIK"));
ui->tableView_clients->setModel(proxyModel);
//ui->tableView_clients->setSortingEnabled(true);
ui->tableView_clients->setColumnWidth(0,20);//ID
ui->tableView_clients->setColumnWidth(1,173);//ClientName
ui->tableView_clients->setColumnWidth(2,110);//ClientCity
ui->tableView_clients->setColumnWidth(3,0);//ClientAddress
ui->tableView_clients->setColumnWidth(4,0);//ClientMol
ui->tableView_clients->setColumnWidth(5,100);//ClientEik
ui->tableView_clients->setColumnWidth(6,0);//ClientVat
ui->tableView_clients->setColumnWidth(7,0);//ClientTel
ui->tableView_clients->setColumnWidth(8,0);//ClientMail
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