Re: [PyQt] Synchronized scrolling between two tables
Note that actionTriggered(int) will return the value before the update. Instead, use valueChanged(int) to get the resulting value in this example. Vitas Povilaitis -- View this message in context: http://python.6.n6.nabble.com/Synchronized-scrolling-between-two-tables-tp1917990p4717071.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronized scrolling between two tables
Thanks Wolfgang and Scott. Wolfgang, Initially I had wanted to use one table. But I couldn't figure out how to disable certain columns. My data goes in the first three columns, then the calculation results are populated in the next 5 columns. I don't want the user to be able to edit/select the calculated 5 columns. That is why I implemented two adjacent tables. If their is a way to disable certain columns in a table from being selected, I would appreciate if you can guide me to it. Thanks again! Bugzilla from wolfg...@rohdewald.de wrote: Am Dienstag, 1. November 2011, 14:02:48 schrieb Nader Abedrabbo: 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? yes. Have a look at classes ScoreViewLeft, ScoreViewRight and ScoreTable in kajongg http://websvn.kde.org/trunk/KDE/kdegames/kajongg/src/scoring.py?view=markup but I do not see the need for two tables in your case, I would try to use one single QTableView. Initialize the calculated fields to empty and after having calculated them, refresh the view. you do not even need a calculate button. If your calculation really needs some time, you can put the calculation into a separate thread and automatically update the view when a field has been calculcated. -- Wolfgang ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt -- View this message in context: http://old.nabble.com/Synchronized-scrolling-between-two-tables-tp32761709p32765646.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronized scrolling between two tables
Am Mittwoch, 2. November 2011, 06:23:36 schrieb Nader Abedrabbo: If their is a way to disable certain columns in a table from being selected, I would appreciate if you can guide me to it. you can define you own model, deriving from a Qt standard model, and override flags(). In the link I gave you there is a file rulesetselector.py which defines a tree view where some items can be edited in different ways (combobox, text, numbers, checkboxes). Your table view should be easier to implement. def flags(self, index): # pylint: disable=R0201 tell the view what it can do with this item if not index.isValid(): return Qt.ItemIsEnabled column = index.column() item = index.internalPointer() content = item.rawContent checkable = False if isinstance(content, Ruleset) and column in (0, 3): mayEdit = True elif isinstance(content, Rule): mayEdit = column in [0, 1, 2, 3] checkable = column == 1 and content.parType is bool else: mayEdit = False mayEdit = mayEdit and not isinstance(item.ruleset(), PredefinedRuleset) result = Qt.ItemIsEnabled | Qt.ItemIsSelectable if mayEdit: result |= Qt.ItemIsEditable if checkable: result |= Qt.ItemIsUserCheckable return result ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronized scrolling between two tables
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-tp32761709p3279.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Synchronized scrolling between two tables
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-tp32761709p32761709.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronized scrolling between two tables
Am Dienstag, 1. November 2011, 14:02:48 schrieb Nader Abedrabbo: 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? yes. Have a look at classes ScoreViewLeft, ScoreViewRight and ScoreTable in kajongg http://websvn.kde.org/trunk/KDE/kdegames/kajongg/src/scoring.py?view=markup but I do not see the need for two tables in your case, I would try to use one single QTableView. Initialize the calculated fields to empty and after having calculated them, refresh the view. you do not even need a calculate button. If your calculation really needs some time, you can put the calculation into a separate thread and automatically update the view when a field has been calculcated. -- Wolfgang ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Synchronized scrolling between two tables
According to the documentation: QTableView.scrollTo (*self*, QModelIndexfile:///C:/Python26/Lib/site-packages/PyQt4/doc/html/qmodelindex.html *index*, QAbstractItemView.ScrollHintfile:///C:/Python26/Lib/site-packages/PyQt4/doc/html/qabstractitemview.html#ScrollHint-enum *hint* = QAbstractItemView.EnsureVisible) I assume you would have to create a QModelIndex based on the first tables' scrolled to record, and then feed it into the second table via a key press (or release) grab? If this is set up to fire for each scrolled record on the first table, it might get resource-intensive to 'synchronize' the scrolling, though. On Tue, Nov 1, 2011 at 2:02 PM, Nader Abedrabbo aenad...@yahoo.com 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-tp32761709p32761709.html Sent from the PyQt mailing list archive at Nabble.com. ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt