Unsolved Form setting preferred size
-
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?
-
@SPlatten said in Form setting preferred size:
show all the columns in the QTableView.
-
@Pl45m4 said in Form setting preferred size:
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?
-
It's been a long while since I used widgets, but could you do this by implementing
sizeHint
, making use ofcontentsRect
? -
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 aQSettings
object, which you read in your constructor and update in your destructor.