Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Resizing QScrollArea to exactly fit contents
qtdev512 last edited by
I've built a program which shows a QScrollArea containing a custom widget. I would like it to make it so that when the program launches, the QScrollArea is exactly the right size to show the contained widget with no scroll bars. But if I try scr.resize(clock.sizeHint()), it's just a little too small and I see scrollbars. How can I avoid this? The gist of my code is below:
Hi and welcome to devnet,
You should rather trigger the resize after it's shown using e.g. a QTimer with a 0 timeout otherwise the sizeHint might give you something not accurate since the widget you are getting the hint from is still invisible.
Hope it helps