Qscrollarea not scrolling

The QScrollArea class provides a scrolling view onto another widget. A scroll area is used to display the contents of a child widget within a frame.

If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed. The child widget must be specified with setWidget. For example:. The code above creates a scroll area shown in the images below containing an image label.

When scaling the image, the scroll area can provide the necessary scroll bars:. The scroll bars appearance depends on the currently set scroll bar policies. You can control the appearance of the scroll bars using the inherited functionality from QAbstractScrollArea. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the horizontalScrollBar and verticalScrollBar functions which enable you to access the scroll bars and set the scroll bars' values whenever the scroll area's contents change, using the QScrollBar::setValue function.

You can retrieve the child widget using the widget function. The view can be made to be resizable with the setWidgetResizable function. The alignment of the widget can be specified with setAlignment. Two convenience functions ensureVisible and ensureWidgetVisible ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary.

When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget is set to a suitable value. If a standard QWidget is used for the child widget, it may be necessary to call QWidget::setMinimumSize to ensure that the contents of the widget are shown correctly within the scroll area.

If a scroll area is used to display the contents of a widget that contains child widgets arranged in a layout, it is important to realize that the size policy of the layout will also determine the size of the widget.

Qt Documentation

This is especially useful to know if you intend to dynamically change the contents of the layout. If this property is set to false the defaultthe scroll area honors the size of its widget. If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.

Scrolls the contents of the scroll area so that the point xy is visible inside the region of the viewport with margins specified in pixels by xmargin and ymargin. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

Scrolls the contents of the scroll area so that the childWidget of QScrollArea::widget is visible inside the viewport with margins specified in pixels by xmargin and ymargin. The widget becomes a child of the scroll area, and will be destroyed when the scroll area is deleted or when a new widget is set. The widget's autoFillBackground property will be set to true.Your browser does not seem to support JavaScript.

As a result, your viewing experience will be diminished, and you may not be able to execute some actions. Please download a browser that supports JavaScript, or enable it if it's disabled i. I have spent two days trying to get a scrollarea to scroll. So currently I am adding 47 labels to the VBox. Have I done something wrong?? I use the QScrollArea in some projects. I found it works quite well but I use a different approach. I create a parent widget and this is put into the scroll area.

QScrollArea tab focus problem

I use a vertical layout but a grid layout would work just the same. The spacer widget at the bottom of my example keeps the children from resizing to fill the parent widget.

In my case the widget containing the scroll area is fixed so I put the spacer inside the scroll area. For me, the spacer solves a problem when you don't have enough children to fill the area.

I dynamically move this to the bottom of all the children that are added as they are added. In your example the sizeHints might be the problem. Maybe the scroll area doesn't realize the size of the widget therefore it doesn't scroll?

So looking at your code it looks like the only difference is adding a QSizePolicy. I implemented that all it did was add a space at the top. The QSizePolicy is part of the constructor for the spacer item text is wrapped around so it looks like a new line. One thing that might be the problem is the parent of the 'widget'.Please share with friends and colleagues! When you start building apps that display long documents, large amounts of data or large numbers of widgets, it can be difficult to arrange things within a fixed-size window.

Resizing the window beyond the size of the screen isn't an option, and shrinking widgets to fit can make the information unreadable. To illustrate the problem below is a window in which we've created a large number of QLabel widgets. These widgets have the size Vertical Policy set to Preferred which automatically resizes the widgets down to fit the available space. The results are unreadable. Settings the Vertical Policy to Fixed keeps the widgets at their natural size, making them readable again.

However, while we can still add as many labels as we like, eventually they start to fall off the bottom of the layout. To solve this problem GUI applications can make use of scrolling regions to allow the user to move around within the bounds of the application window while keeping widgets at their usual size. By doing this an almost unlimited amount of data or widgets can be shown, navigated and viewed within a window — although care should be taken to make sure the result is still usable!

First, create an empty MainWindow in Qt Designer and save it as mainwindow. Next choose to lay out the QScrollArea vertically or horizontally, so that it scales with the window. We will now add labels to that scroll area. Lets take two labels and place it inside the QScrollArea. We will then proceed to right click inside the scroll area and select Lay Out Vertically so our labels will be stacked vertically.

We've set the background to blue so the illustration of this this works is clear. We can now add more labels to the QScrollArea and see what happens. By default, the Vertical Policy of the label is set to Preferred which means that the label size is adjusted according to the constraints of widgets above and below. For example, it's a great way to show multiple widgets containing data in a expansive dashboard, but less appropriate for control widgets — scrolling around to control an application can get frustrating.

Note that the scroll functionality has not been triggered, and no scrollbar has appeared on the right hand side. Instead the labels are still progressively getting smaller in height to accommodate the widgets.

However, if we set Vertical Policy to Fixed and set the minimumSize of height to px the labels will no longer be able to shrink vertically into the available space. As the layout overflows this will now trigger the QScrollArea to display a scrollbar. With that, our scrollbar appears on the right hand side. What has happened is that the scroll area only appears when necessary. Without a fixed height constraint on the widget, Qt assumes the most logical way to handle the many widgets is to resize them.

But by imposing size constraints on our widgets, the scroll bar appears to allow all widgets to keep their fixed sizes.

Qt Documentation Snapshots

Another important thing to note is the properties of the scroll area. Instead of adjusting fixed heights, we can keep it in Preferredwe can set the properties of the verticalScrollBar to ScrollBarAlwaysOn which will enable the scroll bar to appear sooner as below. Saving and running the code at the start of this tutorial gives us this scroll area app which is what we wanted. As with all widgets you can also add a QScrollArea directly from code. Below we repeat the above example, with a flexible scroll area for a given number of widgets, using code.

If you run the above code you should see the output below, with a custom widget repeated multiple times down the window, and navigable using the scrollbar on the right.

First we create our layout hierarchy. This places the QScrollArea in the window, taking up the entire area. To add content to the QScrollArea we need to add a widget using. We allow the widget to be resized, and then add the central placeholder widget to complete the layout. Finally, we will add the QScrollArea as the central widget for our QMainWindow and set up the window dimensions, title and show the window. In this tutorial we've learned how to add a scrollbar with an unlimited number of widgets, programatically or using Qt Designer.

Adding a QScrollArea is a good way to include multiple widgets especially on apps that are data intensize and require objects to be displayed as lists.The QScrollArea class provides a scrolling view onto another widget. A scroll area is used to display the contents of a child widget within a frame.

qscrollarea not scrolling

If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed. The child widget must be specified with setWidget. For example:. The code above creates a scroll area shown in the images below containing an image label. When scaling the image, the scroll area can provide the necessary scroll bars:.

The scroll bars appearance depends on the currently set scroll bar policies. You can control the appearance of the scroll bars using the inherited functionality from QAbstractScrollArea. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the horizontalScrollBar and verticalScrollBar functions which enable you to access the scroll bars and set the scroll bars' values whenever the scroll area's contents change, using the QScrollBar::setValue function.

You can retrieve the child widget using the widget function. The view can be made to be resizable with the setWidgetResizable function. The alignment of the widget can be specified with setAlignment. Two convenience functions ensureVisible and ensureWidgetVisible ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary. When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget is set to a suitable value.

If a standard QWidget is used for the child widget, it may be necessary to call QWidget::setMinimumSize to ensure that the contents of the widget are shown correctly within the scroll area. If a scroll area is used to display the contents of a widget that contains child widgets arranged in a layout, it is important to realize that the size policy of the layout will also determine the size of the widget.

This is especially useful to know if you intend to dynamically change the contents of the layout. If this property is set to false the defaultthe scroll area honors the size of its widget. If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.The QScrollArea class provides a scrolling view onto another widget.

qscrollarea not scrolling

A scroll area is used to display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed. The child widget must be specified with setWidget. For example:. The code above creates a scroll area shown in the images below containing an image label.

When scaling the image, the scroll area can provide the necessary scroll bars:. The scroll bars appearance depends on the currently set scroll bar policies. You can control the appearance of the scroll bars using the inherited functionality from QAbstractScrollArea.

Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the horizontalScrollBar and verticalScrollBar functions which enable you to access the scroll bars and set the scroll bars' values whenever the scroll area's contents change, using the QScrollBar::setValue function. You can retrieve the child widget using the widget function. The view can be made to be resizable with the setWidgetResizable function.

The alignment of the widget can be specified with setAlignment. Two convenience functions ensureVisible and ensureWidgetVisible ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary. When using a scroll area to display the contents of a custom widget, it is important to ensure that the size hint of the child widget is set to a suitable value.

qscrollarea not scrolling

If a standard QWidget is used for the child widget, it may be necessary to call QWidget::setMinimumSize to ensure that the contents of the widget are shown correctly within the scroll area. If a scroll area is used to display the contents of a widget that contains child widgets arranged in a layout, it is important to realize that the size policy of the layout will also determine the size of the widget.

This is especially useful to know if you intend to dynamically change the contents of the layout. If this property is set to false the defaultthe scroll area honors the size of its widget. If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.

Scrolls the contents of the scroll area so that the point xy is visible inside the region of the viewport with margins specified in pixels by xmargin and ymargin. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.

Subscribe to RSS

Scrolls the contents of the scroll area so that the childWidget of QScrollArea::widget is visible inside the viewport with margins specified in pixels by xmargin and ymargin. The widget becomes a child of the scroll area, and will be destroyed when the scroll area is deleted or when a new widget is set. The widget's autoFillBackground property will be set to true. If the scroll area is visible when the widget is added, you must show it explicitly. Note that You must add the layout of widget before you call this function; if you add it later, the widget will not be visible - regardless of when you show the scroll area.

In this case, you can also not show the widget later. Documentation contributions included herein are the copyrights of their respective owners. Qt and respective logos are trademarks of The Qt Company Ltd. All other trademarks are property of their respective owners. This property was introduced in Qt 4.

See also setWidget. This function was introduced in Qt 4. See also widget.For more information about how to perform a clean startup, click one of the following article numbers, as appropriate for your version of Windows:. Select Product Version. All Products. After you try to change the button or scrolling settings for any one of the Microsoft mouse devices that are listed in the "Applies to" section, you experience one of the following issues: All the button assignments are reset to their default settings.

You cannot change the button assignments for your pointing device. Button assignment commands in the IntelliPoint software are unavailable "dimmed". Scrolling is too slow or too fast in specific applications. You receive the following error message: Some mouse settings might not work until you connect a Microsoft mouse to a USB port on your computer or set up a Microsoft mouse that uses Bluetooth technology.

This can be because of any of the following reasons: Incorrect mouse is selected in IntelliPoint software. Conflict with other non-Microsoft mouse or pointer software, Problem with the IntelliPoint software or drivers. Application does not correctly recognize scrolling messages from the mouse. Last Updated: Aug 19, Need more help? No results. Join the discussion Ask the community.

Get support Contact Us. Was this information helpful?

qscrollarea not scrolling

Yes No. Tell us what we can do to improve the article Submit. Your feedback will help us improve the support experience. Australia - English. Bosna i Hercegovina - Hrvatski. Canada - English. Crna Gora - Srpski. Danmark - Dansk. Deutschland - Deutsch. Eesti - Eesti. Hrvatska - Hrvatski. India - English. Indonesia Bahasa - Bahasa. Ireland - English. Italia - Italiano. Malaysia - English. Nederland - Nederlands. New Zealand - English. Philippines - English.

Polska - Polski. Schweiz - Deutsch. Singapore - English. South Africa - English. Srbija - Srpski.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I want to put some elements of my UI in a scroll area as there can be a lot of them.

I tried the following peice of code, but the area just keeps growing as I put more elements on it. In the first part I set up a scroll area, a widget and a layout. I apply the layout to the widget and I set the widget to the scrollarea. Then I fill in my layout in an external function. The button under all of it allows to fill more elements in the layout. I know its too late to answer for this question, but here is a working example and you missing the parent layout.

Learn more. Asked 9 years, 2 months ago. Active 8 years, 3 months ago. Viewed 5k times. QScrollArea scrollRow. QWidget self. QGridLayout self. Any idea? Johanna Johanna 1, 4 4 gold badges 22 22 silver badges 42 42 bronze badges. Active Oldest Votes. QVBoxLayout self self.

QScrollArea self self. QRect 0, 0,self. QHBoxLayout self. QPushButton "Add Items" self. QApplication sys. Achayan Achayan 4, 1 1 gold badge 29 29 silver badges 50 50 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Podcast Ben answers his first question on Stack Overflow. The Overflow Bugs vs. Featured on Meta. Responding to the Lavender Letter and commitments moving forward.


thoughts on “Qscrollarea not scrolling

Leave a Reply

Your email address will not be published. Required fields are marked *