I have created a QTreeWidget with 4 columns using a Designer. It works but my header columns are "1 2 3 4". I tried setHeaderLabels():
{
QStringList labels
= {"title",
"author",
"source",
"date" };
setHeaderLabels(labels);
TreeHeader = header(); // TreeHeader is QHeaderView *
TreeHeader->setSectionHidden(1,true);
TreeHeader->setSectionHidden(2,true);
TreeHeader->setSectionHidden(3,true);
TreeHeader->setVisible(false);
}
Tree::Tree( QWidget *parent ) : QTreeWidget(parent)
{
QStringList labels = {"title", "author", "source", "date" };
setHeaderLabels(labels);
TreeHeader = header(); // TreeHeader is QHeaderView *
TreeHeader->setResizeMode(0,QHeaderView::Stretch);
TreeHeader->setSectionHidden(1,true);
TreeHeader->setSectionHidden(2,true);
TreeHeader->setSectionHidden(3,true);
TreeHeader->setVisible(false);
}
To copy to clipboard, switch view to plain text mode
(At the beginning: we have no header and only one column in the view.) but I still have columns "1 2 3 4". Perhaps, because setHeaderLabels() adds columns instead of updating them according to the documentation. I have searched something what updates header labels but I have found nothing. How should I set the header labels?
Bookmarks