Issue
I want to scroll in two different QListWidgets
simultaneously by using only one QScrollBar
. One way could be to connect the QScrollBar
changeValue()
Signal to both QListWidgets
, but I don't know how to do it.
Different solutions are welcome too (but there must be two QListWidgets
)
GUI Example
Solution
You just need to connect the valueChanged
signal of the scroll bar of one list widget to setValue
method of the another list widget's scrollbar. Doing so will scroll the second list widget whenever the first list widget is scrolled.
You need to do this for both the list-widgets so that scrolling of any list widget scrolls the other.
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QListWidget, QApplication
class Window(QWidget):
def __init__(self):
super(Window, self).__init__()
self.setupUI()
self.list1.addItems(['Asia Pacific', 'Europe', 'Middle East', 'Africa', 'America']*5)
self.list2.addItems(['AP', 'EU', 'ME', 'AF', 'AM']*5)
self.list1.verticalScrollBar().valueChanged.\
connect(self.list2.verticalScrollBar().setValue)
self.list2.verticalScrollBar().valueChanged.\
connect(self.list1.verticalScrollBar().setValue)
def setupUI(self):
layout = QHBoxLayout(self)
self.list1 = QListWidget(self)
self.list2 = QListWidget(self)
layout.addWidget(self.list1)
layout.addWidget(self.list2)
self.setLayout(layout)
if __name__=="__main__":
import sys
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())
Answered By - ThePyGuy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.