Issue
I have searched the archives and I found the following code:
class ManifestModel: public QSqlTableModel
{
public:
ManifestModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase() ):
QSqlTableModel(parent, db)
{ }
~ManifestModel() { }
Qt::ItemFlags flags ( const QModelIndex & index ) const
{
if (index.column() == 2)
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
else
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
};
Then use ManifestModel in place of QSqlTableModel.
This does exactly what I need to do, but I don't understand C++ syntax. Could someone please convert this to Python for me. I would really appreciate it.
Solution
This is what works in PyQt5:
class ManifestModel(QtSql.QSqlTableModel):
def __init__(self, parent=None, db=QtSql.QSqlDatabase()):
super(ManifestModel, self).__init__(parent, db)
def flags(self, index):
if (index.column() == 4):
return QtCore.Qt.ItemIsEnabled
elif (index.column() == 6):
return QtCore.Qt.ItemIsEnabled
else:
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
Answered By - nlgootee
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.