Before I posted I spent a couple hours looking online, reading the docs,
and trying different ways.
I found one person that said they did it but their syntax didn't work.
But it doesn't throw an error either.
model.setData(model.index(tblRow, col), font, Qt.FontRole)
When I'm done with my app (nearly 2K LOC) I'm going to put a summary out
there somewhere with a bunch of examples of easy ways to do things. For
one thing I wrote zero classes. Not one.
> I've never
> worked with a QTableView, so I had to start with some knowledge about
> some other parts of QT. I found the first page searching for "qt set
> qtableview row font", and the second searching for "qtablewidgetitem".
I used TableWidgets in 2 apps and no problems. In this app there's more
data and more sorting, and one of the TableWidgets took a while to load
35K rows (7 items per row). So I tried a TableView. Incredibly fast -
4x the speed - but it doesn't have the bolding in place yet. That could
slow it down.
As you know, a TableView is tied to the underlying datasource (in my
case via a QSqlTableModel), but it's much faster to show data than a
TableWidget, because with the widget you have populate each cell with
setItem().
The Widget is slower but easier to work with. So it's a tradeoff.
And I think I found some bugs in the TableViews. The Views have
editStrategies() that control how data is updated (if the model supports
editing), but they don't work the way the docs say they do.
In my app, when I click on a row a flag field is changed from N to Y
onscreen (well, it's hidden but it's in the row).
model.setData(model.index(row,7), 'Y')
OnFieldChange : all changes to the model will be applied immediately to
the database.
model.setEditStrategy(QSqlTableModel.OnFieldChange)
Doesn't work right. The screen is updated the first row you click on,
but the db isn't updated until you reload the view.
OnRowChange : changes to a row will be applied when the user selects
a different row.
model.setEditStrategy(QSqlTableModel.OnRowChange)
Doesn't work right. The screen is updated the first row you click on,
but the db isn't updated until you reload the view.
OnManualSubmit : all changes will be cached in the model until either
submitAll() or revertAll() is called.
model.setEditStrategy(QSqlTableModel.OnManualSubmit)
This works the best: the screen changes on each row I click, but the db
isn't updated even if I do submitAll() right after setData(). Have to
reload the view for the changes to propagate to the db.
Since none work as they say, the issue is probably on my end. Don't know.
I just ended up issuing a quick SQL UPDATE statement for the row.
If you really want speed use the read-only QSqlQueryModel(). Loads 35K
rows to screen in 1/2 a second (but no bolding applied - I really have
to figure that out, as it's a central feature of the GUI)
Thanks for your help.