Python Forum
[PyQt] How do I get a QScrollArea to scroll?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] How do I get a QScrollArea to scroll?
#4
I cannot run your example (I have PySide2) and translating to PySide2 is difficult because of how you use the designer (which I hate hate hate hate designer code).

This is a short example of a working scrollable area.
import sys
import PySide2.QtWidgets as QtWidgets
from PySide2.QtCore import Qt

class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.view = QtWidgets.QWidget()
        self.layout = QtWidgets.QVBoxLayout(self.view)
        self.scroll = QtWidgets.QScrollArea(self)
        self.scroll.setWidgetResizable(True)
        self.scroll.setWidget(self.view)
        self.setCentralWidget(self.scroll)
        for i in range(20):
            self.layout.addWidget(QtWidgets.QLabel('Make this a fairly wide Label '+str(i)))
     
app = QtWidgets.QApplication(sys.argv)
ui = MyWindow()
ui.show()
sys.exit(app.exec_())
The important parts are that the scrolled widget is larger than the scrollable area and that the scrollable area knows how big the scrolled widget is (setWidgetResizeable(True)).

Looking at your example I think the problem is that the scrolled widget is not larger than the scrollable area. I'm guessing that ui.scrollAreaWidgetContents is your scrolled widget (a QWidget?). I see where you place things in this widget but I don't see where the widget is resized. I would stop using setGeometry and use a layout manager instead. That will automatically grow the scrolled widget as needed.
Reply


Messages In This Thread
RE: How do I get a QScrollArea to scroll? - by deanhystad - Oct-24-2021, 02:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] QScrollArea does not work HeinKurz 3 1,415 Jan-24-2023, 09:45 PM
Last Post: HeinKurz
  [PyQt] QTableView: scroll to top cell of the screen random_nick 2 2,898 Oct-08-2022, 12:29 AM
Last Post: random_nick
  Treeview scroll selected node to top rfresh737 1 2,742 Apr-14-2021, 03:27 AM
Last Post: deanhystad
  [Tkinter] canvas widget scroll issue chrisdb 2 3,916 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  [Tkinter] Help with scroll bars kraco 1 2,264 Sep-27-2020, 11:20 PM
Last Post: Larz60+
  [Tkinter] How to place scroll bar correctly scratchmyhead 1 3,985 May-18-2020, 04:17 PM
Last Post: scratchmyhead
  Scroll frame with MouseWheel Nemesis 1 3,661 Mar-25-2020, 09:29 PM
Last Post: Nemesis
  [Kivy] Why I have to click twice to scroll? Hummingbird 0 2,389 Jan-06-2020, 09:08 PM
Last Post: Hummingbird
  [Tkinter] Scroll Bars going backwards goofygoo 2 2,728 Jun-07-2019, 05:07 PM
Last Post: goofygoo
  [PyQt] QScrollArea with a gridlayout littleGreenDude 2 10,032 Jan-28-2019, 07:14 PM
Last Post: littleGreenDude

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020