Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Resizing QScrollArea to exactly fit contents

Resizing QScrollArea to exactly fit contents

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtdev512
    wrote on last edited by
    #1

    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:

    AnalogClock clock;
    QScrollArea scr;
    scr.setWidget(&clock);
    scr.resize(clock.sizeHint());
    scr.show()

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved