[PyQt] Subclassing QSqlQueryModel, making one column checkable

2009-08-16 Thread Sibylle Koczian
Hello,

I want to do the following: get two normal columns and one boolean
expression computed by a subquery from my database table, put them into
a QSqlQueryModel and show one of the columns in a QListView. Works so far.

But I'd like to make this column checkable. At the start of the
application the state should depend on the value of my boolean
expression in another column. I get so far with the code shown below.

But then the user should be able to check and uncheck items in the view,
without changing either the text in the column or the value of the
boolean column of the model. I suppose I should overwrite setData, just
for the CheckStateRole, but how?

Or would it be better to use a QStandardItemModel, because
QStandardItems have all the methods I need?

Here is the code for the model:

class EigReiseModel(QtSql.QSqlQueryModel):

def flags(self, index):
flags = QtSql.QSqlQueryModel.flags(self, index)
if index.column() == 1:
flags |= QtCore.Qt.ItemIsUserCheckable
return flags

def data(self, index, role=QtCore.Qt.DisplayRole):
zl = index.row()
if index.column() == 1 and role == QtCore.Qt.CheckStateRole:
idx2 = self.createIndex(zl, 2)
if self.data(idx2).toBool():
return QtCore.Qt.Checked
else:
return QtCore.Qt.Unchecked
else:
return QtSql.QSqlQueryModel.data(self, index, role)

##def setData(self, index, value, role=QtCore.Qt.EditRole):
##if index.column() == 1 and role == QtCore.Qt.CheckStateRole:
##chk = value.toBool()
##if chk:
##??? (check item, but how?)

Thank you for all hints,
Sibylle

-- 
Sibylle Koczian


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Rating widget

2009-08-16 Thread Carlos Gonçalves
Hi,

I've ported the rating widget from the Nepomuk KDE project (written in C++) to 
Python and also get rid of the pykde4 dependency, meaning all is in pyqt4 now.

Find this widget in http://websvn.kde.org/trunk/KDE/kdelibs/nepomuk/core/ui/

So, after ported it and coded a simple test case, I found out that the widget 
doesn't get displayed (invisible) but it is there though - mouse events are 
triggered properly and emit the 'ratingChanged' signal outputting the current 
rating value. I'm wondering what am I missing or coding wrong...

Sources: www.cgoncalves.info/trash/rating.tar.bz2

Thanks!

-- 
Regards,
Carlos Gonçalves

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Re: Rating widget

2009-08-16 Thread Carlos Gonçalves
On Sunday 16 August 2009 18:45:46 Carlos Gonçalves wrote:
> So, after ported it and coded a simple test case, I found out that the
>  widget doesn't get displayed (invisible) but it is there though - mouse
>  events are triggered properly and emit the 'ratingChanged' signal
>  outputting the current rating value. I'm wondering what am I missing or
>  coding wrong...

Fixed. ratingPainter.py line 133: condition has to be false to be executed.

-- 
Regards,
Carlos Gonçalves

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt