Results 1 to 3 of 3

Thread: QStandardItem: Setting Top Column Data?

  1. #1
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QStandardItem: Setting Top Column Data?

    I am using QStandardItem and QStandardModel for my data model. I like this much better than the base QAbstractItemView because of the Item class that I can use to treat clumps of data as a single object, but I can't figure out how to get any data into columns other than the root column on the first row.

    Example Code:
    Qt Code:
    1. class QMyModel : public QStandardItemModel
    2. {
    3. Q_OBJECT
    4. public:
    5. QMyModel(QObject *parent) : QStandardItemModel(parent) {};
    6. virtual ~QMyModel();
    7.  
    8. enum Columns
    9. {
    10. COLUMN_NAME,
    11. COLUMN_CUSTOM,
    12. NUM_COLUMNS
    13. };
    14. };
    15.  
    16. class QMyItem : public QStandardItem
    17. {
    18. QMyItem(QString Name, QString Description, QString First, QString Second)
    19. {
    20. setData(Name, Qt::DisplayRole);
    21. // TODO: Put Description beside Name and make editable in TreeView.
    22. setChild(0, QMyModel::COLUMN_NAME, "First:");
    23. setChild(0, QMyModel::COLUMN_CUSTOM, First);
    24. setChild(1, QMyModel::COLUMN_NAME, "Second:");
    25. setChild(1, QMyModel::COLUMN_CUSTOM, Second);
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    This results in the following for the QTreeView with QMyItem("Item Name", "A Simple Item", "String 1", "String 2"):

    + Item Name
    - - First: | String 1
    - - Second: | String 2

    How do I get it to look like this:
    + Item Name | A Simple Item
    - - First: | String 1
    - - Second: | String 2

    And is there a way to do it within the QStandardItem, instead of having to go back to the parent view?

    Thank you for your assistance.
    Last edited by AaronMK; 24th January 2008 at 18:46. Reason: reformatted to look better

  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: QStandardItem: Setting Top Column Data?

    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QStandardItem: Setting Top Column Data?

    Quote Originally Posted by jpn
    See QStandardItemModel::setItem(int row, int column, QStandardItem* item). Notice the column parameter.
    A couple problems with this:
    1. During construction, there is no parent model.
    2. There is no slot or virtual function that is triggered when the Item is attached to a model, so delaying construction of that item is not an option.


    True, I could pass the parent to the constructor, insert it manually (Which row?), create the QStandardItem for the second item of the top column for Description, and set Description as a child or sibling of the main item. At that point, I might as well go back to the basic QAbstractModel, and would lose the modularity that I am trying to get by using QStandardItem in the first place.

Similar Threads

  1. setting data of buffer to QTreeWidget column
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 18:12
  2. Sql Server cannot retrieve data from select
    By Atomino in forum Qt Programming
    Replies: 10
    Last Post: 7th September 2006, 17:37
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 13:53
  4. Setting Delegates per Column
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 30th May 2006, 22:39

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.