Answer the question
In order to leave comments, you need to log in
How to display in QTableWidget the required row in the middle of the visible area of the table?
A PyQt4 application connects to a sqlite database with a single table and processes a query to select all records for which a unique value of the vec column is entered in qlineedit and, in addition to this desired record, a number of records are displayed before and after it.
Extract from code:
##############################
from PyQt4 import QtCore, QtGui
import sys, MyForm
import sqlite3
cnn = sqlite3. connect('sqlite/data.sqlite')
c = cnn.cursor()
class Prog(QtGui.QWidget, MyForm.Ui_MyForm):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self .setupUi(self)
self.btnSrch.clicked.connect(self.outputResults)
def outputResults(self):
c.execute("select * from data where vec>? and vec<?", (vec1,vec2,))
# then populate the qtablewidget with the query results and navigate to the desired record using the following method:
for i in xrange(self.tableWidget0.columnCount()):
self.tableWidget0.scrollToItem(self.tableWidget0.item(vec,i))
#################### #######################################
_ With scrollToItem, the item being searched is displayed either at the top or bottom of the visible area of the table, depending on whether the searched item is currently above or below the visible one. How can I make the required record always appear in the middle of the visible area of the table?
Answer the question
In order to leave comments, you need to log in
scrollToItem(self.tableWidget0.item(vec,i), QtCore.QAbstractItemView.PositionAtCenter)
try
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question