Results 1 to 4 of 4

Thread: Using QAbstractItemView

  1. #1
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Using QAbstractItemView

    Hi
    I have a data structure that looks like (this will grow)

    Identity
    Location (string)
    Name (string)
    Company (string)
    Tool Type (enumeration)
    Configuration
    Spacing (int)
    Offset (int)
    Reference (int)

    I have a struct to store these values.
    I want to display this in a QTreeView to allow the suer to edit them.
    To this end I created a subclass of QAbstractItemModel but am now having problems implementing the virtual methods. For example i cant figure out what to do in the index() method.
    I am wrong to use QAbstractItemModel ?
    Is there a better way?

    TIA

    Graham
    Additional Information

  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: Using QAbstractItemView

    If you don't feel comfortable with implementing your own model, use QStandardItemModel.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    107
    Thanks
    22
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using QAbstractItemView

    Thanks for your reply
    As a first attempt I did this
    Qt Code:
    1. QStandardItem *parentItem = model.invisibleRootItem();
    2. for (int i = 0; i < 4; ++i) {
    3. QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
    4. parentItem->appendRow(item);
    5. parentItem = item;
    6. }
    7.  
    8. QTreeView *treeView = new QTreeView(this);
    9. treeView->setModel(&model);
    To copy to clipboard, switch view to plain text mode 
    The treeView is displayed but contains no data

    what might I have missed

    Graham

  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: Using QAbstractItemView

    Your model goes out of scope.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QAbstractItemView
    By dima in forum Qt Programming
    Replies: 0
    Last Post: 11th October 2010, 09:00
  2. Replies: 3
    Last Post: 26th November 2009, 18:28
  3. QAbstractItemView
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2009, 12:30
  4. QAbstractItemView
    By defumar in forum Newbie
    Replies: 9
    Last Post: 22nd January 2008, 13:50
  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.