Search code examples
pythonpython-3.xqtpyqtpyqt5

how to make the application accept scrolling by touching in PyQt5?


I have an application made by PyQt5 and this application is used by customers use touch screen , without keyboard or mouse only screen and they touch on it to move and to do everything.

my application has QScrollArea and this QScrollArea contains choices and i need to scroll up and down to be able to see all of the choices, but my customers are not able to scroll when they touch on the screen and pull it down or raise it up (for example like google chrome) :

enter image description here

but my application does not accept that when i do it on my touch screen :

enter image description here

i know that i have a scroll bar on the window but it is not comfort when all the time you need to scroll down you have to go to a specific place to scroll down.

do you have a solution ?

this is a code to test it out only:


from PyQt5 import QtWidgets
import sys


app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.resize(500,500)
window_layout = QtWidgets.QGridLayout()


scrollarea = QtWidgets.QScrollArea()



frame = QtWidgets.QFrame()
frame_layout = QtWidgets.QGridLayout()

button1 = QtWidgets.QPushButton()
button1.setStyleSheet("background-color:rgb(150,0,0);")
button1.setFixedSize(200,200)

button2 = QtWidgets.QPushButton()
button2.setStyleSheet("background-color:rgb(150,0,0);")
button2.setFixedSize(200,200)

button3 = QtWidgets.QPushButton()
button3.setStyleSheet("background-color:rgb(150,0,0);")
button3.setFixedSize(200,200)

button4 = QtWidgets.QPushButton()
button4.setStyleSheet("background-color:rgb(150,0,0);")
button4.setFixedSize(200,200)

frame_layout.addWidget(button1)
frame_layout.addWidget(button2)
frame_layout.addWidget(button3)
frame_layout.addWidget(button4)
frame.setLayout(frame_layout)



scrollarea.setWidget(frame)


window_layout.addWidget(scrollarea)
window.setLayout(window_layout)
window.show()
app.exec()

thanks


Solution

  • i solved the problem.

    thanks to who helped me :

    1- musicamante

    2- Github guy

    i added this code after the QScrollArea:

    QtWidgets.QScroller.grabGesture(scrollarea.viewport(),QtWidgets.QScroller.LeftMouseButtonGesture)
    

    this is the whole code:

    
    from PyQt5 import QtWidgets
    import sys
    
    
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QWidget()
    window.resize(500,500)
    window_layout = QtWidgets.QGridLayout()
    
    
    scrollarea = QtWidgets.QScrollArea()
    
    
    
    frame = QtWidgets.QFrame()
    frame_layout = QtWidgets.QGridLayout()
    
    button1 = QtWidgets.QPushButton()
    button1.setStyleSheet("background-color:rgb(150,0,0);")
    button1.setFixedSize(200,200)
    
    button2 = QtWidgets.QPushButton()
    button2.setStyleSheet("background-color:rgb(150,0,0);")
    button2.setFixedSize(200,200)
    
    button3 = QtWidgets.QPushButton()
    button3.setStyleSheet("background-color:rgb(150,0,0);")
    button3.setFixedSize(200,200)
    
    button4 = QtWidgets.QPushButton()
    button4.setStyleSheet("background-color:rgb(150,0,0);")
    button4.setFixedSize(200,200)
    
    frame_layout.addWidget(button1)
    frame_layout.addWidget(button2)
    frame_layout.addWidget(button3)
    frame_layout.addWidget(button4)
    frame.setLayout(frame_layout)
    
    
    
    scrollarea.setWidget(frame)
    
    QtWidgets.QScroller.grabGesture(scrollarea.viewport(), QtWidgets.QScroller.LeftMouseButtonGesture)
    
    
    window_layout.addWidget(scrollarea)
    window.setLayout(window_layout)
    window.show()
    app.exec()
    
    

    and yes it worked.