Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
Form setting preferred size
SPlatten last edited by
I have a form / dialog derived from QWidget, the form contains a QTableView and under this is a QScrollArea which contains tabs and pages. I wrote this quite a while ago and now I've been asked to set adjust the default size of the window so it defaults to the required width to show all the columns in the QTableView.
I was looking at setting the size policy and setting a preferred width, what are the related methods called for setting the preferred width?
Pl45m4 last edited by
show all the columns in the QTableView.
SPlatten last edited by SPlatten
That works fine for adjusting the columns to fit the content, thank you, how can I get the form to adjust to accommodate the QTableView so I don't have to scroll horizontally?
Bob64 last edited by
It's been a long while since I used widgets, but could you do this by implementing
sizeHint, making use of
AxelVienna last edited by
As Bob64 said,
setSizeHint(const QSize &)is the way to define a widget's preferred size. A widget's runtime size is also depends the widget's size policy. If the widget is held by a layout, the layout type and (if existing) other widgets and their sizes are also considered. This is why setting a size hint does not necessarily lead to predictable column sizes of your list view.
In case you want that, you can set the column sizes directly by
setColumnWidth(int column, int width). A user-friendly way to remember widget sizes for the next session is to store them in a
QSettingsobject, which you read in your constructor and update in your destructor.