[PyQt] PyQt - How to preload values to a QTableView

Anil anilet at gmail.com
Mon Oct 13 12:50:53 BST 2008


Hi
I have a QTableView that is showing some data from a MySQL database and I am 
trying to use it to add new values to the table.
How can I preload some of the fields with available information like UserName 
and date rather than asking user to enter it.
I tried to preset in  

 def setModelData(self, editor, model, index):
        if index.column() == WDAY:
            data= "9" #just trying
            model.setData(index, QVariant(data))
        else:
            QSqlRelationalDelegate.setModelData(self, editor, model,
                                                index)

but unless user clickes on the cell the data is not filled in.

Or can I use (From Qt Assistant)
-----------------------------------------------------
bool QSqlRelationalTableModel::setData ( const QModelIndex & index, const 
QVariant & value, int role = Qt::EditRole ) 
Sets the data for the role in the item with the specified index to the value 
given. Depending on the edit strategy, the value might be applied to the 
database at once, or it may be cached in the model.
Returns true if the value could be set, or false on error (for example, if 
index is out of bounds).
For relational columns, value must be the index, not the display value.
----------------------------------------------------------
I tried to use this method and could not make it to work 
----
 if index.column() == WDAY:
            date = self.calenderDay.selectedDate()
            data =  date.day()
            if (self.hourModel.setData(index ,Qvariant(data) , 
Qt.DisplayRole)):
                print "Error setData %s" % (hourModel.lastError()).text()
----
I just Picked up the Rapid GUI Programming With PyQt a few week back and am 
certainly a Newbee at Python.

Regards,
Anil K Thankappan
anilet at gmail.com
Visit our website :gallery.phoenixitsolutions.com.au 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081013/78b72271/attachment.html


More information about the PyQt mailing list