QTableView Stretch Headers but keep Interactive
-
I am struggling triying to accomodate my QTableView to make it easy to the user.
This functions works as i really need:
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
The issue with this is that the headers are not user adjustable anymore, are completely frozzen.I know we also have this function which allows the user to adjust the Headers, but after using it, the headers go back as if i had not used QHeaderView::Stretch before:
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
I have really looked for this on many websites with no luck of finding a understandable answer for my level.Thanks!
-
Hi Guys, after Struggling like 3 hours ive got it:
for(int c = 0;c<=4;c++){ ui->tableView->horizontalHeader()->resizeSection(c, 150); } ui->tableView->horizontalHeader()->setStretchLastSection(true);
Set first the width of each column to match the QTableView size and then Stretch the last section, thanks a lot!
-
I am struggling triying to accomodate my QTableView to make it easy to the user.
This functions works as i really need:
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
The issue with this is that the headers are not user adjustable anymore, are completely frozzen.I know we also have this function which allows the user to adjust the Headers, but after using it, the headers go back as if i had not used QHeaderView::Stretch before:
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
I have really looked for this on many websites with no luck of finding a understandable answer for my level.Thanks!
@Adan895 said in QTableView Stretch Headers but keep Interactive:
That is what https://doc.qt.io/qt-5/qheaderview.html#ResizeMode-enum says,Interactive
(the user can resize) andStretch
(widths are set to fill view) are different from/incompatible with each other. So perhaps you will have to explain exactly what you mean by your "Stretch Headers but keep Interactive"? -
Hi and welcome to devnet,
Are you triggering a resize to content size somehere in your code ?
-
@Adan895 said in QTableView Stretch Headers but keep Interactive:
That is what https://doc.qt.io/qt-5/qheaderview.html#ResizeMode-enum says,Interactive
(the user can resize) andStretch
(widths are set to fill view) are different from/incompatible with each other. So perhaps you will have to explain exactly what you mean by your "Stretch Headers but keep Interactive"? -
@JonB Hi, i want to Stretch the headers to the size of the QTableview, but allow the user to adjust them if necessary.
-
Hi and welcome to devnet,
Are you triggering a resize to content size somehere in your code ?
-
@SGaist Hello, no, i am just stretching the headers to the QTableview size using QHeaderView::Stretch, but if i do that the user cannot resize the Headers if necessary manually.
-
@SGaist Hello, no, i am just stretching the headers to the QTableview size using QHeaderView::Stretch, but if i do that the user cannot resize the Headers if necessary manually.
-
Hi Guys, after Struggling like 3 hours ive got it:
for(int c = 0;c<=4;c++){ ui->tableView->horizontalHeader()->resizeSection(c, 150); } ui->tableView->horizontalHeader()->setStretchLastSection(true);
Set first the width of each column to match the QTableView size and then Stretch the last section, thanks a lot!