[SOLVED] QTableView - Resize of several columns
-
Hello,
i would like to know if it exists any way to change the width of several columns at the same time. I mean that the user can select several columns and when he resizes one of this, it resizes other columns selected. I don't know if i am understandable.
-
You are understandable - you are talking about something that exists in MS Excel for example, right? AFAIK there's no such option available straight out of the box. But implementing one shouldn't be too much of a hassle. Just derive from QTableView and create your own class where you can implement that option.
Edit: typos.
-
Yes, exactly the same option exists in MS Excel. The problem is I don't find any signal called when a column is resized but only a slot :
@void QTableView::columnResized ( int column, int oldWidth, int newWidth ) [protected slot]@So I don't understand how exploit such slot in order to realize what i mean.
-
Its not what you want, but using that you resize the columns.
@ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);@
-
There is a signal emitted after resizing the columns:
@void QHeaderView::sectionResized ( int logicalIndex, int oldSize, int newSize ) [signal]@
You can connect to that one and create a slot where you will resize all selected columns accordingly. -
Perfect, it works now but the user must select all the column not only some rows:
the connect :
@connect (tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(onColumnResized(int, int, int)));
@the slot :
@void MyClass::onColumnResized (int logicalIndex, int oldSize, int newSize)
{
unsigned int d;if( sender() == tableView->horizontalHeader()) { int nbColSelected = tableView->selectionModel()->selectedColumns(0).size(); int size = tableView->columnWidth(tableView->horizontalHeader()->visualIndex(logicalIndex));
for(d = 0; d < nbColSelected; ++d)
{
tableView->setColumnWidth( tableView->selectionModel()->selectedColumns(0)[d].column(), size );
}
}
}@ -
Umm, do you still have a problem? Cause I can't really tell from your post if this problem is solved or not ;-).
-
Hum no it's perfect :)
Where can I put "SOLVED" my topic? I don't find.
-
Just edit your first post.
-
Thanks for all d2uriel.
-
You are welcome. Glad I could be of help.