[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] QTableWidget.selectRow() not always highlighting selected
From: Kerri Reno <kreno () yumaed ! org>
Date: 2009-06-30 20:12:32
Message-ID: a5b8c7860906301312h2a84f0dbi57005ef33faca387 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Attached is a reproducible example of my problem. It simulates a table with
10 existing rows, and the user has clicked on an 'Add New' button (not
shown). The UI added a new line to the table. If I then click on a
different line, the UI asks if I want to abort my add. When I say 'No', the
code does a selectRow, to get back to the newly added row, but the row that
I clicked on still shows as highlighted, even though currentRow shows the
last, newly added row. I believe the newly added row should now be
highlighted, but I can't seem to make that happen.
I hope this makes sense. I know it's a bit convoluted, but hopefully when
you run the app it will make more sense.
Is this a bug? Or am I missing something? Anything you can do to help
would be sincerely appreciated.
TIA,
Kerri
--
Yuma Educational Computer Consortium
Compass Development Team
Kerri Reno
kreno@yumaed.org (928) 502-4240
.·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·.
[Attachment #5 (text/html)]
Attached is a reproducible example of my problem. It simulates a table with 10 \
existing rows, and the user has clicked on an 'Add New' button (not shown). \
The UI added a new line to the table. If I then click on a different line, the UI \
asks if I want to abort my add. When I say 'No', the code does a selectRow, \
to get back to the newly added row, but the row that I clicked on still shows as \
highlighted, even though currentRow shows the last, newly added row. I believe the \
newly added row should now be highlighted, but I can't seem to make that \
happen.<br> <br>I hope this makes sense. I know it's a bit convoluted, but \
hopefully when you run the app it will make more sense. <br><br>Is this a bug? Or \
am I missing something? Anything you can do to help would be sincerely \
appreciated.<br> <br>TIA,<br>Kerri<br><br>-- <br>Yuma Educational Computer \
Consortium<br>Compass Development Team<br>Kerri Reno<br><a \
href="mailto:kreno@yumaed.org">kreno@yumaed.org</a> (928) 502-4240<br>.·:*¨¨*:·. \
.·:*¨¨*:·. .·:*¨¨*:·.<br>
--0022152d6531456cce046d966df6--
["test.py" (text/x-python)]
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class testUI(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self,parent)
self.resize(QSize(QRect(0,0,506,445).size()).expandedTo(self.minimumSizeHint()))
self.centralwidget = QWidget(self)
self.hboxlayout = QHBoxLayout(self.centralwidget)
self.tableWidget = QTableWidget(self.centralwidget)
self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tableWidget.setObjectName("tableWidget")
self.hboxlayout.addWidget(self.tableWidget)
self.setCentralWidget(self.centralwidget)
self.tableWidget.clear()
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(0)
self.restoringRow = False
vheader = self.tableWidget.verticalHeader()
vheader.hide()
for count in xrange(10):
row = self.tableWidget.rowCount()
self.tableWidget.insertRow(row)
self.tableWidget.selectRow(row)
self.tableWidget.setRowHeight(row,22)
item = QTableWidgetItem(str(count))
self.tableWidget.setItem(row,0,item)
item = QTableWidgetItem('Line %s' % count)
self.tableWidget.setItem(row,1,item)
item = QTableWidgetItem('True')
self.tableWidget.setItem(row,2,item)
self.connect(self.tableWidget,
SIGNAL('currentCellChanged(int,int,int,int)'),
self.newLineSelected)
self.show()
self.addNew()
def addNew(self):
row = self.tableWidget.rowCount()
self.tableWidget.insertRow(row)
self.tableWidget.selectRow(row)
self.tableWidget.setRowHeight(row,22)
item = QTableWidgetItem('---')
item.setData(Qt.UserRole,QVariant(-1))
self.tableWidget.setItem(row,0,item)
item = QTableWidgetItem('<<New Line Add in Progress>>')
item.setData(Qt.UserRole,QVariant(-1))
self.tableWidget.setItem(row,1,item)
item = QTableWidgetItem('---')
item.setData(Qt.UserRole,QVariant(-1))
self.tableWidget.setItem(row,2,item)
self.tableWidget.resizeColumnsToContents()
self.addingNewLine = True
def newLineSelected(self,row,col,orow,ocol):
if self.restoringRow:
self.restoringRow = False
return
if row == orow or self.tableWidget.item(row,0) == None:
return
if self.addingNewLine:
msgBox = QMessageBox(QMessageBox.NoIcon,
'Testing',
'You have begun a New Line\n' \
'Do you want to Abort this action?',
QMessageBox.Yes| QMessageBox.No)
response = msgBox.exec_()
if response == QMessageBox.No:
self.restoringRow = True
print 'selecting row %s' % orow
self.tableWidget.selectRow(orow)
return
self.addingNewLine = False
if __name__ == '__main__':
app = QApplication(sys.argv)
win = testUI()
win.show()
app.exec_()
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic