how to set columnWidth correctly without having to use StretchMethods on a QTableView
-
Hello i'm currently working on an interface with QTableViews in it and i'm having a hard time to deal with the columns. the thing is, i would like the cells to be the same size and to fill the whole Table. i cannot use SetStretchLastSection because the last cell will be uneven when i stretch my table view, and if i set my my QHeaderView to Stretch, the datas will be unreadable when i shrink my table view because there won't be any scroll bar displaying. in summary, how can i get my cells to be the same size without having the last one uneven or having to use QHeaderView::Stretch ?
-
Retrieve the width of the view and resize your sections to fill the whole view.
-
Retrieve the width of the view and resize your sections to fill the whole view.
@Christian-Ehrlicher i thought about that but the witdh of my view is interactive. if i stretch it during the program it wont be fitting my cells anymore
-
@Christian-Ehrlicher i thought about that but the witdh of my view is interactive. if i stretch it during the program it wont be fitting my cells anymore
@aftalib Then you have to adjust your others accordingly after the resize.
-
-
What's wrong with QHeaderView::resizeSection()?
-
What's wrong with QHeaderView::resizeSection()?
@Christian-Ehrlicher i tried it but SetStretchLastSection overrides resizeSection() : no matter if i put interactive, stretch or fixed, the last section is still wider than the other ones when i stretch it .
-
Then don't use setStretchLastSection
-
Then don't use setStretchLastSection
@Christian-Ehrlicher but if i do so my cells wont fill my QTableView
-
@Christian-Ehrlicher but if i do so my cells wont fill my QTableView
@aftalib said in how to set columnWidth correctly without having to use StretchMethods on a QTableView:
but if i do so my cells wont fill my QTableView
That's why I said 'Then you have to adjust your others accordingly after the resize.'
-
@aftalib said in how to set columnWidth correctly without having to use StretchMethods on a QTableView:
but if i do so my cells wont fill my QTableView
That's why I said 'Then you have to adjust your others accordingly after the resize.'
@Christian-Ehrlicher yes that's what i want to do but i dont really know how to do this with the available functions
-
@aftalib said in how to set columnWidth correctly without having to use StretchMethods on a QTableView:
how to do this with the available functions
What are you missing? Getting the size of the view? How you resize a section was already answered:
What's wrong with QHeaderView::resizeSection()?
-
here's what happens when i set resizeSection() to interactive :

i have worse or even results with Stretch or Fixed.
to get the size of the view i do : QRect rect2 = ui->tableView->frameGeometry();
is this correct ?
thank you for taking the time to answer me
-
my solution was to set the maximum width of each of my tableviews by the number of the future columns plus the vertical header width, the problem is when i stretch the window the last tableview is going away on the right as you can see here :

and i have no explanation for this to happen. each of these tableviews have the exact same settings
-
my solution was to set the maximum width of each of my tableviews by the number of the future columns plus the vertical header width, the problem is when i stretch the window the last tableview is going away on the right as you can see here :

and i have no explanation for this to happen. each of these tableviews have the exact same settings
-
you can make fixed size , setcolumn size
ui.tableView_1->setColumnWidth(4, 130);
ui.tableView_1->setColumnWidth(3, 110);
ui.tableView_1->setColumnWidth(2, 120);
ui.tableView_1->setColumnWidth(1, 120);
ui.tableView_1->setColumnWidth(0, 120);
Are you using layout for tables in mainwindow? -
you can make fixed size , setcolumn size
ui.tableView_1->setColumnWidth(4, 130);
ui.tableView_1->setColumnWidth(3, 110);
ui.tableView_1->setColumnWidth(2, 120);
ui.tableView_1->setColumnWidth(1, 120);
ui.tableView_1->setColumnWidth(0, 120);
Are you using layout for tables in mainwindow?