PDA

View Full Version : QTableView and checkboxes



ibergmark
22nd February 2008, 18:47
Hi all,

I have a QTableView where I've created my own delegate to draw checkboxes for a column. I re-implemented paint() and use drawCheck(...) inside.

I have two problems;

1) The checkox is not immediately accessible when I click on a cell, I have to double-click the cell to activate the editor. What can I do to make the checkbox active immediately so the the user can just click once to toggle the value?

2) The editor becomes left-justified in the cell (see attachment). I want it to be centered just like the paint() method draws them.


Any advice would be appreciated.

Thanks,
Ingemar

jpn
22nd February 2008, 18:58
Hi, I'd suggest taking a look at src/gui/itemviews/qitemdelegate.cpp, especially QItemDelegate::editorEvent(). The delegate should handle check states without editors.

ibergmark
23rd February 2008, 02:29
Hi, I'd suggest taking a look at src/gui/itemviews/qitemdelegate.cpp

Shucks...I keep forgetting that I have the original source code for the framework :o

I have converted recently from the Microsoft .NET framework, where if I had a problem, there was no way to find out how the framework accomplished something.
IMHO, not only does Qt surpass .NET, but it has the added benefit of learning the framework by reading the source.

The fact that the apps can be compiled for multiple platforms is icing on the cake :D

Thanks again for a great forum!
/ Ingemar

ibergmark
23rd February 2008, 15:20
Hi again,

I've got everything working now with my delegate, however there is one very annoying thing that happens after a field has been updated:
The whole view re-populates itself!

I want to have the change commited to the database immediately so I have set my editStrategy to OnFieldChange. If I change to OnManualSubmit it works as expected.

I looked at the original source code and the QSqlTableModel does a select() after an update when the editStrategy is OnFieldChange.

What I'm wondering about is what happens if you use a QSqlTableModel to edit a large table? After scrolling far down the list and then edit a field, the view is re-populated and the position is lost, so you have to scroll down again :confused:
Is it really like this, or have I missed something?

Regards,
/ Ingemar