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. QScrollArea and Custom Widget - No scrollbars
Forum Updated to NodeBB v4.3 + New Features

QScrollArea and Custom Widget - No scrollbars

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.2k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    ThE_-_BliZZarD
    wrote on last edited by
    #1

    Hello everybody.

    I know this question has been asked before but all those hints did not answer my question.

    I have a QScrollArea as an Element on my Main Window. It gets resized with the windows itself.
    Insided the Scrollarea I placed a custom widget that I created by inheriting from QWidget. This custom widget has a fixed size, but may change this size from time to time. I want the ScrollArea to show ScrollBars if the inner custom Widget is too big to fit.

    What commands do I have to add to a) my widget and b) the ScrollArea to achieve this?

    Sadly, the hint in the docs about setting an appropriate Size Hint did not do anything for me.

    My current Code looks like this:
    Main Class:
    @
    ui.displayWidgetScrollArea->setWidgetResizable(true);
    this->labyrinthWidget = new LabyrinthWidget(this->labyrinth, ui.displayWidgetScrollArea);
    this->labyrinthWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    ui.displayWidgetScrollArea->setBackgroundRole(QPalette::Dark);
    @

    Inside the LabyrinthWidget, called whenever the Widgets need to change its size:
    @
    int locWidth = someValueCalculatedHere;
    int locHeight = someValueCalculatedHere;
    this->resize(locWidth, locHeight);
    this->setMinimumSize(locWidth, locHeight);
    this->setMaximumSize(locWidth, locHeight);
    this->update();
    @

    Qt 5.0, MSVC2012 Update 1.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      To add the widget to the scroll area, use QScrollArea::setWidget.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThE_-_BliZZarD
        wrote on last edited by
        #3

        This simple and simplistic one sentence answer just nearly made me cry.

        Yes, this is the solution, now it works just as expected.
        Thanks a lot :) You made my day!

        @
        ui.displayWidgetScrollArea->setWidgetResizable(true);
        this->labyrinthWidget = new LabyrinthWidget(this->labyrinth, ui.displayWidgetScrollArea);
        this->labyrinthWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        ui.displayWidgetScrollArea->setBackgroundRole(QPalette::Dark);
        ui.displayWidgetScrollArea->setWidget(this->labyrinthWidget);
        @

        A small question remains: Why was the widget displayed before? It was there and showed the correct contents...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          steno
          wrote on last edited by
          #4

          Probably because of parenting. If you make a parent visible, the children will become visible.

          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