Thanks, Mark, that's closer. But it still only shows part of the note, 'emergency broadcast system'.<br><br><div><span class="gmail_quote">On 1/12/08, <b class="gmail_sendername">Mark Summerfield</b> <<a href="mailto:mark@qtrac.eu">
mark@qtrac.eu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 2008-01-11, Kerri Reno wrote:<br>> Below is my code. The first column wraps, but the third column doesn't,
<br>> and shows ....<br>><br>> What am I doing wrong? I would like both columns to wrap.<br><br>(1) After you've set word wrap you need to call:<br><br> self.setTextElideMode(Qt.ElideNone)<br><br> This stops PyQt making long texts short by inserting an ellipsis
<br><br>(2) Do not call resizeColumnsToContents()<br><br> The call you have is pointless anyway because you resize before<br> you've got any data, but if you call this after you have data the<br> columns will simply grow as wide as needed and you'll get a
<br> horizontal scrollbar<br><br>(3) Call resizeRowsToContents() whenever the model's data changes (or at<br> least after the initial data is loaded)<br><br> This is to ensure that each row is tall enough to show the wrapped
<br> text.<br><br>from PyQt4.QtGui import *<br>from PyQt4.QtCore import *<br>import sys<br><br>class notesView(QTableView):<br><br> def __init__(self,parent, notes):<br> QTableView.__init__(self,parent)<br>
self.setSizePolicy(QSizePolicy.Preferred,<br> QSizePolicy.Fixed)<br><br> v = self.verticalHeader()<br> v.hide()<br><br> self.model = notesModel(notes)<br> self.setWordWrap(True)<br>
self.setTextElideMode(Qt.ElideNone) # ADD<br># self.resizeRowsToContents()<br># self.resizeColumnsToContents()<br> self.setModel(self.model)<br><br>class notesModel(QAbstractTableModel):<br><br> def __init__(self, notes):
<br> QAbstractTableModel.__init__(self)<br> self.notes = notes<br><br> def flags(self,index):<br> if not index.isValid():<br> return Qt.ItemIsEnabled<br> return Qt.ItemFlags(QAbstractTableModel.flags
(self,index))<br><br> def rowCount(self, index=QModelIndex()):<br> return len(self.notes)<br><br> def columnCount(self,index=QModelIndex()):<br> return 3<br><br> def headerData(self,section,orientation,role=
Qt.DisplayRole):<br> if role == Qt.TextAlignmentRole:<br> if orientation == Qt.Horizontal:<br> return QVariant(int(Qt.AlignHCenter|Qt.AlignVCenter))<br> return QVariant(int(Qt.AlignRight|Qt.AlignVCenter
))<br> if role != Qt.DisplayRole:<br> return QVariant()<br> if orientation == Qt.Horizontal:<br> if section == 0:<br> return QVariant('Date')<br> elif section == 1:
<br> return QVariant('Author')<br> elif section == 2:<br> return QVariant('Note')<br> return QVariant(int(section+1))<br><br> def data(self,index,role=Qt.DisplayRole
):<br> if not index.isValid() or not (0 <= index.row() < len(self.notes)):<br> return QVariant()<br><br> note = self.notes[index.row()]<br> column = index.column()<br><br> if role ==
Qt.DisplayRole:<br> if column == 0:<br> return QVariant(QString(note['stamp']))<br> elif column == 1:<br> return QVariant(QString("%1,<br>%2").arg(note['last_name'],note['first_name']))
<br> elif column == 2:<br> return QVariant(QString(note['note']))<br> elif role == Qt.TextAlignmentRole:<br> return QVariant(int(Qt.AlignLeft|Qt.AlignVCenter))<br><br> return QVariant()
<br><br>if __name__ == '__main__':<br><br> app = QApplication(sys.argv)<br> form = QDialog()<br> notes_list = [{'id':1,<br> 'stamp': '1/3/2008 4:31:04 PM',<br> 'last_name':'Blow',
<br> 'first_name':'Joe',<br> 'note':'This is a test of the emergency broadcast system. This<br>is only a test.'}]<br> notes = notesView(form, notes_list)<br> notes.resizeRowsToContents
() # ADD<br> notes.setMinimumWidth(400)<br> notes.setMinimumHeight(200)<br> form.show()<br> app.exec_()<br><br><br><br>--<br>Mark Summerfield, Qtrac Ltd., www.qtrac.eu<br><br></blockquote></div><br><br clear="all">
<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>.·:*¨¨*:·. .·:*¨¨*:·. .·:*¨¨*:·.