PDA

View Full Version : QTableView how to move columns with code



Marco
5th May 2009, 11:21
Hi, I want to rearrange some columns of a QTableView after setting the QTableModel. I want to exchange column 1 with 2. How I can do that? :confused:
Thanks

spirit
5th May 2009, 11:27
have a look at QHeaderView::swapSections.

Marco
5th May 2009, 11:38
Thank you!



QHeaderView *headerView = tableView->horizontalHeader();
headerView->swapSections(2, 1);

aamer4yu
5th May 2009, 12:47
Also have a look at QHeaderView::moveSection

little_su
10th May 2012, 03:19
QxTableView::QxTableView(QWidget *parent)
: QTableView(parent)


void QxTableView::moveSection(int from, int to)
{
verticalHeader()->moveSection(from, to);
}

void QxTableView::swapSections(int first, int second)
{
verticalHeader()->swapSections(first , second);
}

Nadsa
28th March 2016, 13:00
Thank you!



QHeaderView *headerView = tableView->horizontalHeader();
headerView->swapSections(2, 1);


Thank you.. Working AS is.. :)