PDA

View Full Version : QAbstractItemView



defumar
21st January 2008, 16:11
Hi,

I was looking for a good book, tutorial or post which explains me how to exactly implement a very own view based on the QAbstractItemView class.

I've read the reference page about it and identified which pure virtuals I should implement but the reference is still too vague for me about when they are called by the framework and what they should do or return.

I have had a look at the wiki page about qt and am currently thinking of buying Foundations of Qt Development, unless ofcourse some kind person would give me a good tutorial, guide or post about QAbstractItemView.

I am familiar with C++ and MFC GUI programming

Thanks in advance.

jpn
21st January 2008, 17:43
Did you notice Chart Example (http://doc.trolltech.com/latest/itemviews-chart.html)? PieView is a QAbstractItemView subclass.

defumar
21st January 2008, 18:13
Hmm, yes. I've looked at it before, but it doesn't quite give you info about when the functions are called by the framework or any other in depth info.

jpn
21st January 2008, 18:28
I agree, model-view docs don't cover very well if at all writing a custom view. Custom models and delegates are common but people rarely need to write custom views.

Edit: PS. Just ask if you have any specific questions about certain methods or so.. :)

wysota
21st January 2008, 18:45
I agree, model-view docs don't cover very well if at all writing a custom view.

It's quite easy to deduce which methods will be called when once you know what they do.

defumar
22nd January 2008, 09:24
Well I'm writing some sort of a Form View for my ToDo app. The app works with a database which contains a bunch of tasks. A task consists of a title, an rich text formatted description and some more data about when it should be finished.
The app will have two views: a Form View and a standard QListView with a header, I guess.

The form view consists of various widgets. It's got a model set to it which contains the current selection of the QListView, i.e. the current task (title, description, date it should be finished, ...).

The list view has a different model set to it, an enumeration of all tasks in the database (title and id only).

My main questions are:
Is it a good idea to make a form view or should I use something else?
When are the following functions called:

indexAt(const QPoint & point) const
scrollTo(const QModelIndex & index, ScrollHint hint)
visualRect(const QModelIndex & index) const
moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
visualRegionForSelection(const QItemSelection & selection) const


Many thanks in advance

jpn
22nd January 2008, 09:39
Have you noticed QDataWidgetMapper? It provides mapping between model and widgets. With help of QDateWidgetMapper it should be easy to create any kind of form which contains widgets working directly on top of database model.

defumar
22nd January 2008, 10:05
Hadn't noticed it, no. Will have a look at it right now
Edit: Looks very useful, I now understand why so little people want to make their own view :)

wysota
22nd January 2008, 13:06
indexAt(const QPoint & point) const
Pointer operations like clicking and selection.


scrollTo(const QModelIndex & index, ScrollHint hint)
All kinds of ensureVisible, scrolling the viewport and changing item focus


visualRect(const QModelIndex & index) const
Mainly redrawing.


moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
Editing and key input events.


visualRegionForSelection(const QItemSelection & selection) const
Redrawing.

When in doubt, just use grep.

defumar
22nd January 2008, 13:50
Thanks you two, oh and grep and Qt are awesome :-)
Can't believe I've been messing around with MFC for so long :o