Results 1 to 10 of 10

Thread: QAbstractItemView

  1. #1
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default QAbstractItemView

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAbstractItemView

    Did you notice Chart Example? PieView is a QAbstractItemView subclass.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: QAbstractItemView

    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.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAbstractItemView

    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..
    Last edited by jpn; 21st January 2008 at 18:32.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractItemView

    Quote Originally Posted by jpn View Post
    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.

  6. #6
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: QAbstractItemView

    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

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QAbstractItemView

    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.
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    defumar (22nd January 2008)

  9. #8
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: QAbstractItemView

    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
    Last edited by defumar; 22nd January 2008 at 10:14.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractItemView

    Quote Originally Posted by defumar View Post
    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.

  11. The following user says thank you to wysota for this useful post:

    defumar (22nd January 2008)

  12. #10
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    3

    Default Re: QAbstractItemView

    Thanks you two, oh and grep and Qt are awesome :-)
    Can't believe I've been messing around with MFC for so long

Similar Threads

  1. QAbstractItemView questions
    By krudio in forum Qt Programming
    Replies: 12
    Last Post: 15th January 2008, 10:32
  2. QAbstractItemView problem
    By Kostanev in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2007, 22:32
  3. [qt-4.2] question on QAbstractItemView
    By someralex in forum Qt Programming
    Replies: 12
    Last Post: 19th December 2006, 15:41
  4. How change the DropIndicator of QAbstractItemView
    By Wan-Hi in forum Qt Programming
    Replies: 3
    Last Post: 20th March 2006, 19:58
  5. setContentsMargins in QAbstractItemView
    By Promethee in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2006, 14:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.