Results 1 to 5 of 5

Thread: Subclassing QAbstractItemView

  1. #1
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Subclassing QAbstractItemView

    Hi

    All last week I was struggling to learn the Model-View framework and find a way to solve my problem with it's help. Basically I need to layout some editable graphical UI elements (arrows, circles, text blocks, etc) on a grid. The layout is supposed to be nested - i.e. some grid cell may contain another grid of UI elements. The M/V framework seems to be exactly what I need - QAbstractiItemModel allows to define nested or recursive layout. I also created several item delegates which draw my geometric primitives and allow me to edit text blocks. Now I'm stuck with the front-end side of things. It looks like any of the existing implementations of QAbstractItemView does not support displaying nested models, so I looked for implementing QAbstractItemView.

    There is no QAbstractItemView subclassing reference. Right now I'm trying to subclass it and display my nested model using the delegate classes I created, but it seems to be a complicated task.

    What is necessary to implement such a view?

    Thanks
    Anton

    P.S.
    I searched the forums. This question seems to be pretty common, but I have not found an explanation or an example.

  2. #2
    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: Subclassing QAbstractItemView

    If you are after graphics, it might be easier to use QGraphicsView.

  3. #3
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Subclassing QAbstractItemView

    Quote Originally Posted by wysota View Post
    If you are after graphics, it might be easier to use QGraphicsView.
    Yes, I'm after graphics, but interactive graphics, plus editable text. Basically I'm working on kind of a flow-chart editor. I believe it's quite complicated to implement it solely using QGraphicsView..

    Edit:
    Stupid question.. I should have checked QGraphicsView earlier! Probably I will go for it. Thanks!

    But still my question about QAbstractModelView is open. How complicated is it to subclass it? I looked at the Chart example, but painting in the example is implemented directly in the View paintEvent, but I want to draw using delegates.
    Last edited by psih128; 11th October 2008 at 17:50.

  4. #4
    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: Subclassing QAbstractItemView

    Quote Originally Posted by psih128 View Post
    Yes, I'm after graphics, but interactive graphics, plus editable text.
    That's another argument to use graphics view.

    Basically I'm working on kind of a flow-chart editor. I believe it's quite complicated to implement it solely using QGraphicsView..
    On the contrary

    But still my question about QAbstractModelView is open. How complicated is it to subclass it? I looked at the Chart example, but painting in the example is implemented directly in the View paintEvent, but I want to draw using delegates.
    Painting items using delegates is easy. The most complicated things are mapping between indexes and their positions on screen. Take a look at my custom view: http://www.wysota.eu.org/charts.html. It doesn't use delegates per se but a very similar concept.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QAbstractItemView

    You can also have a look at the Diagram scene example under Graphics View in Qt Demos

Similar Threads

  1. Replies: 2
    Last Post: 26th February 2009, 11:12
  2. QAbstractItemView
    By defumar in forum Newbie
    Replies: 9
    Last Post: 22nd January 2008, 14:50
  3. QAbstractItemView questions
    By krudio in forum Qt Programming
    Replies: 12
    Last Post: 15th January 2008, 11:32
  4. Subclassing QScrollView
    By sumsin in forum Qt Programming
    Replies: 13
    Last Post: 16th March 2006, 15:20
  5. setContentsMargins in QAbstractItemView
    By Promethee in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2006, 15: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.