If attached a QLineEdit in the cell, I lose cell/item signals, because QLineEdit in top of it.
I think I achieved my goal:
ui(new Ui::Store)
{
ui->setupUi(this);
Store::setupBill();
....
}
void Store::setupBill()
{
.....
ui->billTableWidget->setCellWidget(0, 1, item);
Items items(ui);
cmpter->setCaseSensitivity(Qt::CaseInsensitive);
cmpter
->setCompletionMode
(QCompleter::PopupCompletion);
item->setCompleter(cmpter);
connect(cmpter,
SIGNAL(activated
(QString)),
this,
SLOT(suggestionItems
(QString)));
}
Store::Store(QWidget *parent) : QMainWindow(parent),
ui(new Ui::Store)
{
ui->setupUi(this);
Store::setupBill();
....
}
void Store::setupBill()
{
.....
QLineEdit *item = new QLineEdit;
ui->billTableWidget->setCellWidget(0, 1, item);
Items items(ui);
lst = new QStringList(items.getItems());
cmpter = new QCompleter(*lst, item);
cmpter->setCaseSensitivity(Qt::CaseInsensitive);
cmpter->setCompletionMode(QCompleter::PopupCompletion);
item->setCompleter(cmpter);
connect(cmpter, SIGNAL(activated(QString)), this, SLOT(suggestionItems(QString)));
}
To copy to clipboard, switch view to plain text mode
First I setup QTableWidget with an attached QLineEdit. Then I connected the activated signal of QCompleter with my SLOT void suggestionItems(QString):
void Store
::suggestionItems(QString itm
) {
PrintBill bill(ui);
bill.getItem(itm);
int row = ui->billTableWidget->rowCount();
ui->billTableWidget->insertRow(row);
itemR
->setText
(QString::number(1));
ui->billTableWidget->setItem(row - 1, 3, itemR);
ui->billTableWidget->setCellWidget(row, 1, item);
cmpter->setCaseSensitivity(Qt::CaseInsensitive);
cmpter
->setCompletionMode
(QCompleter::PopupCompletion);
item->setCompleter(cmpter);
}
void Store::suggestionItems(QString itm)
{
PrintBill bill(ui);
bill.getItem(itm);
int row = ui->billTableWidget->rowCount();
ui->billTableWidget->insertRow(row);
QTableWidgetItem *itemR = new QTableWidgetItem;
itemR->setText(QString::number(1));
ui->billTableWidget->setItem(row - 1, 3, itemR);
QLineEdit *item = new QLineEdit;
ui->billTableWidget->setCellWidget(row, 1, item);
cmpter->setCaseSensitivity(Qt::CaseInsensitive);
cmpter->setCompletionMode(QCompleter::PopupCompletion);
item->setCompleter(cmpter);
}
To copy to clipboard, switch view to plain text mode
Witch my SLOT will fill the empty cells of current row, and then insert a new row attached with QLineEdit and QCompleter.
Bookmarks