[PyQt] Synchronized scrolling between two tables
Nader Abedrabbo
aenader1 at yahoo.com
Wed Nov 2 15:50:34 GMT 2011
Thanks Guys,
I found the solution to my problem.
By linking to the tables scroll bar via (QScrollBar) I now have access to
the bar. Then using the signals emitted by the slider via (QAbstractSlider)
I can get the current location of the bar and then sync the other table with
it.
Here is a short example (right table syncs with left, I just need to add
another signal for left table to synch with right).
#########################################
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import time
class MyWindow(QWidget):
def __init__(self, *args):
QWidget.__init__(self, *args)
self.tableWidget1 = QTableWidget()
self.tableWidget2 = QTableWidget()
numRows = 40
numCols = 2
self.tableWidget1.setRowCount(numRows)
self.tableWidget1.setColumnCount(numCols)
self.tableWidget2.setRowCount(numRows)
self.tableWidget2.setColumnCount(numCols)
layout = QHBoxLayout(self)
layout.addWidget(self.tableWidget1)
layout.addWidget(self.tableWidget2)
self.setLayout(layout)
self.sliderBar1 = self.tableWidget1.verticalScrollBar()
self.sliderBar2 = self.tableWidget2.verticalScrollBar()
QObject.connect(self.sliderBar1,
SIGNAL("actionTriggered(int)"),
self.SyncScroll)
def SyncScroll(self):
sliderValue = self.sliderBar1.value()
self.sliderBar2.setValue(sliderValue)
def main():
app = QApplication(sys.argv)
w = MyWindow()
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
#########################################
Nader Abedrabbo wrote:
>
> Greetings,
>
> I have a program where two tables are shows next to each other. One
> program is used to get user data, while the second table is used to show
> the results of the data after certain calculations are performed on the
> original data (via a calculate button). The list of data in the tables
> can be in the hundreds. I added buttons to scroll to the bottom and top of
> the table.
>
> What I would like though is a synchronized scrolling of the two tables,
> i.e. if I scroll the first table, then the second table should scroll to
> the same view (same row level) as the first table.
>
> Is that possible?
>
> Thanks,
> Nader
>
>
--
View this message in context: http://old.nabble.com/Synchronized-scrolling-between-two-tables-tp32761709p32766669.html
Sent from the PyQt mailing list archive at Nabble.com.
More information about the PyQt
mailing list