Results 1 to 6 of 6

Thread: Qt C++ ScrollArea

  1. #1
    Join Date
    Jan 2019
    Posts
    4

    Question Qt C++ ScrollArea

    I have begun using Qt to construct a GUI for a C++ program that I have written. I have widgets that go down past where the screen of my computer goes and want to be able to scroll down to these widgets when I run my program. I have placed all of my objects in a scroll area and selected both vertical and horizontal scroll bar as “always on” but still can’t scroll down to my widgets. Any help is much appreciated.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt C++ ScrollArea

    Any help is much appreciated.
    How did you add these widgets to the scroll area? Did you create a composite widget (a QWidget with a layout and children) and did you add that QWidget using QScrollArea::setWidget()?

    The Qt Image Viewer example shows how to properly use a QScrollArea with scrolling and resizing to fit an image.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt C++ ScrollArea

    QScrollArea provides a scrolling view over a single widget. You will not be able to (need to) scroll in either direction unless the size of that single widget is larger than the available screen space occupied by the QScrollArea.

    You will need to demonstrate how you "placed all of my objects in a scroll area" and how you have placed the scroll area on screen.

    Edit: distracted for a few minutes and beaten to the punch by d_stranz.

  4. The following user says thank you to ChrisW67 for this useful post:

    d_stranz (3rd January 2019)

  5. #4
    Join Date
    Jan 2019
    Posts
    4

    Default Re: Qt C++ ScrollArea

    I simply dragged the scroll area onto the main window anddragged my objects onto the scroll area in the Qt designer - no code.

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt C++ ScrollArea

    I simply dragged the scroll area onto the main window and dragged my objects onto the scroll area in the Qt designer - no code.
    Well that probably created an incorrect configuration for the scroll area. If you open the .ui file as text (not a GUI view), you will see the XML that the designer writes when creating the UI. If the scroll area was done correctly, you should see a hierarchy that starts with your QMainWindow, inside that should be the QScrollArea (and the centralWidget), inside that should be a single QWidget (the one the scroll area manages), inside that should be some kind of layout, and finally inside that should be your widgets that the layout will manage.

    If all you did was add the scroll area to the main window, you'll probably see the first two levels, but then inside the scroll area will be multiple widgets at the same level. That isn't something the QScrollArea can handle correctly.

    I would suggest that you do the following:

    In Qt Creator:

    - derive a new GUI class from QWidget, call it whatever you want that makes sense. This will be the widget managed by the scroll area.

    In Qt Designer:

    - add an appropriate layout to that new widget using the designer
    - add the child widgets for your UI inside the layout
    - save it all
    - you will end up with .ui, .h, and .cpp files for this new widget

    Back in Qt Designer:

    - in your main window code, add the scroll area as the central widget
    - add a plain old QWidget to the scroll widget
    - promote that QWidget to whatever you have named your new widget.
    - save it all and build

    If you have the scroll area set to use scrolling automatically, then as you reduce the size of the main window to smaller than your new widget, the scrollbars should appear and you can scroll the content.
    Last edited by d_stranz; 3rd January 2019 at 17:22.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #6
    Join Date
    Jan 2019
    Posts
    4

    Default Re: Qt C++ ScrollArea

    Thank you so much for your help. I'll try this out and see how it goes.

Similar Threads

  1. ScrollArea in a tabWidget
    By Yaoming in forum Newbie
    Replies: 16
    Last Post: 20th January 2014, 20:51
  2. Help me about QGridLayout and ScrollArea
    By homerux in forum Newbie
    Replies: 3
    Last Post: 12th August 2013, 01:11
  3. Stucked on ScrollArea
    By Asus_G72GX in forum Qt Programming
    Replies: 6
    Last Post: 16th January 2013, 13:12
  4. scrollArea
    By skizzik in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2011, 13:55
  5. QTreeWidget without the ScrollArea?
    By Paalrammer in forum Newbie
    Replies: 5
    Last Post: 13th February 2007, 20:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.