connect
QHeaderView::sortIndicatorChanged ( int logicalIndex, Qt::SortOrder order ) [signal]
signal to other table slot, you will get logical index form this signal then sort your 2nd table with that logical index.
table2.sort( column , Qt::AscendingOrder );
Sample:
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->t1->setSortingEnabled(true); // t1 & t2 are QTableWidget's
ui->t2->setSortingEnabled(true);
connect(ui->t1->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortIndicatorChangedSlot(int,Qt::SortOrder)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::sortIndicatorChangedSlot(int col, Qt::SortOrder sortType)
{
ui->t2->sortByColumn(col, sortType);
}
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->t1->setSortingEnabled(true); // t1 & t2 are QTableWidget's
ui->t2->setSortingEnabled(true);
connect(ui->t1->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortIndicatorChangedSlot(int,Qt::SortOrder)));
}
Widget::~Widget()
{
delete ui;
}
void Widget::sortIndicatorChangedSlot(int col, Qt::SortOrder sortType)
{
ui->t2->sortByColumn(col, sortType);
}
To copy to clipboard, switch view to plain text mode
Bookmarks