What I try to accomplish is a scrollarea full of labels and you can swipe through them using QScroller. The error I got is TypeError: arguments did not match any overloaded call: setSnapPositionsX(self, Iterable[float]): first argument of unbound method must have type 'QScroller' .
class mainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
uic.loadUi("form.ui", self)
self.scroll_area = QScrollArea(self)
self.scroll_area.setStyleSheet(f"font-size : 90px; font-weight : bold")
self.scroll_area.setAlignment(Qt.AlignCenter)
self.scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.layoutt = QHBoxLayout(self)
self.layoutt.addWidget(self.scroll_area)
self.scroll_widget = QWidget(self)
self.scroll_layout = QHBoxLayout(self.scroll_widget)
self.scroll_area.setGeometry(QRect(100,300,900,160))
for i in range(1,50):
self.scroll_layout.addWidget(QLabel("0.{} ".format(i)))
self.scroll_area.setWidget(self.scroll_widget)
QScroller.grabGesture(
self.scroll_area.viewport(), QScroller.LeftMouseButtonGesture
)
QScroller.setSnapPositionsX(self.scroll_area.scroll(self.scroll_area), 0.0, 10.0)
app = QApplication(sys.argv)
win = mainWindow()
win.show()
sys.exit(app.exec_())
Now I know that the first argument in QScroller.setSnapPositionsX(self.scroll_area.scroll(self.scroll_area), 0.0, 10.0) is wrong, thus, this specific function accepts a QScroller type of parameter as the first argument. The problem is I cannot instantiate QScroller in a way scroll = QScroller() it gives the error TypeError: PyQt5.QtWidgets.QScroller cannot be instantiated or sub-classed. What exactly I should write to the first parameter of the setSnapPositionX function?