I need to handle columns widths resizing in QTableWidget
.
How can I do this?
--
I talk about event when cursor is under border between to header sections, left mouse button is down and mouse is moving.
I need to handle columns widths resizing in QTableWidget
.
How can I do this?
--
I talk about event when cursor is under border between to header sections, left mouse button is down and mouse is moving.
Try to connect ui->tableWidget->verticalHeader()
(it returns QHeaderView
) sectionResized()
signal to some slot.
Working examples:
New signal and slots syntax + lambda expressions
connect(ui->tableWidget->horizontalHeader(),&QHeaderView::sectionResized,[=]( int logicalIndex, int oldSize, int newSize) {//with lambda
qDebug() << "works" << logicalIndex << oldSize << newSize;
});
Output:
works 0 115 116
works 0 116 115
works 1 100 101
works 1 101 102
Also add CONFIG += c++11
to the pro file.
Example with old syntax:
In header:
private slots:
void clicked(int, int, int);
In constructor:
connect(ui->tableWidget->horizontalHeader(),SIGNAL(sectionResized(int,int,int)),this, SLOT(clicked(int,int,int)));
Slot:
void MainWindow::clicked(int logicalIndex, int oldSize, int newSize)
{
qDebug() << "works" << logicalIndex << oldSize << newSize;
}
Output:
works 0 106 107
works 0 107 108
works 1 100 101
works 1 101 102
works 1 102 103
Choose the best for you, but note that new syntax has:
See more information: http://qt-project.org/wiki/New_Signal_Slot_Syntax