2 Attachment(s)
Implement custom tree/table header view to support filtering on columns
Hi all,
I want custom header view for my tree/table view like in the attachment, I want to show a line edit below the each column header so that use can filter on each column by entering text into the line edit.
I tried with delegate & came to know that delegate can't work with QHeaderView, so tried other ways also they really didn't work.
what is the best way to achieve this, If I need to customize the QHeaderView, what are the functions I need to re-implement ?
Attachment 11808
Thanks in the advance.
Re: Implement custom tree/table header view to support filtering on columns
hide existing view header.
Have a custom header, It is nothing but QTableView with 1 row & no.of columns your original view has. for this table view set Lined edits as cell widgets so that we will have line edits below headers where we can type & use as filter.
We need to connect few sig/slots in order to sync b/w this header & our main view.
Code:
{
Q_OBJECT
public:
CustomHeader
(int columnCount
= 0,
QWidget *parent
= 0) {
l->setContentsMargins(0,0,0,0);
l->setSpacing(0);
l->addWidget(table);
table->setFixedHeight(55);
for(int i=0; i<columnCount; i++)
{
DelayedLineEdit* lineEdit = new DelayedLineEdit(this);
lineEdit->setDelay(700);
lineEdit->setIndex(i);
table->setCellWidget(0, i, lineEdit);
connect(lineEdit,
SIGNAL(delayTextChanged
(QString)),
this,
SLOT(applyColumnFilter
(QString)));
}
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table->verticalHeader()->hide();
setLayout(l);
setFixedHeight(50);
}
private:
};
{
Q_OBJECT
public:
{
// Horizontal header treatement:
header()->hide();
m_header = new CustomHeader(m_treeModel->columnCount(), this);
}
~treeView();
protected:
setViewportMargins(0,60, 0, 0);
m_header->setGeometry(0, 0, viewport()->width(), m_header->sizeHint().height());
}
setViewportMargins(0, m_header->sizeHint().height(), 0, 0);
m_header->setGeometry(0, 0, viewport()->width(), m_header->sizeHint().height());
}
private:
CustomHeader *m_header;
};