Issue
I have a QTableWidget in PyQT5 and I need to go to a specific visual position of the table.
How could I do it?
When I say visual I mean to give the row and column,then see on the table the given row and column visually
Solution
You have to use the scrollToItem
method, in the next part I show an example:
class Widget(QWidget):
def __init__(self, *args, **kwargs):
QWidget.__init__(self, *args, **kwargs)
hlayout = QHBoxLayout()
self.rbox = QSpinBox(self)
self.cbox = QSpinBox(self)
hlayout.addWidget(self.rbox)
hlayout.addWidget(self.cbox)
vlayout = QVBoxLayout(self)
vlayout.addLayout(hlayout)
nrows = 50
ncols = 30
self.rbox.setMaximum(nrows-1)
self.cbox.setMaximum(ncols-1)
self.table = QTableWidget(nrows, ncols, self)
vlayout.addWidget(self.table)
for r in range(nrows):
for c in range(nrows):
it = QTableWidgetItem("{}-{}".format(r, c))
self.table.setItem(r, c, it)
self.rbox.valueChanged.connect(self.moveToItem)
self.cbox.valueChanged.connect(self.moveToItem)
def moveToItem(self):
it = self.table.item(self.rbox.value(), self.cbox.value())
self.table.scrollToItem(it)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.