Results 1 to 4 of 4

Thread: QStandardItemModel principle

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default QStandardItemModel principle

    Hello,

    I am currently trying to figure out how to structure my widget and probably need a little help. This is not about a detailed implementation.

    I have data that needs to be displayed in a QTreeView. It contains two rows, and is 2 levels deep.
    The second row should be able to contain a QLabel, QLineEdit, QCheckBox or a QComboBox.

    Qt Code:
    1. invisibleRootItem
    2. --> ParentItem1
    3. --> Child 1 QCheckBox
    4. --> Child 2 QLabel
    5. --> Child 3 QLineEdit
    6. ....
    7. --> ParentItem2
    8. --> ParentItem3
    To copy to clipboard, switch view to plain text mode 

    However, I am not completely sure how to access individual items and the state of their 2 row (QCheckBox, QLineEdit...).
    There will be about 100 QStandardItems in the Model, and it feels like storing a pointer to each one is not the solution.
    So how can I clearly identify the individual QStandardItem within the model to set the parameters in the second row, or read their content?

    Thank you in advance.

    bmn

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QStandardItemModel principle

    I think you are confusing the model with the visualization of the model in a tree view. It is the QAbstractItemView that supports displaying QWidget instances (as delegates) when editing the view of the model.

    However, if what you want is to be able to display a checkbox, then use QStandardItem::setCheckable(). To allow the text to be edited in a QLineEdit equivalent, use QStandardItem::setEditable(). A label is just a QStandardItem with editable set to false.

    You can set these flags at any time, but it is usually done when items are added to the model.

  3. #3
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QStandardItemModel principle

    That does not answer my main question of how to keep track of the items.

    I also need a QComboBox, therefore I would need the delegate to view it as such, right?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStandardItemModel principle

    Normally, the widget used by an item view to edit data in the underlying model is created as required when editing mode is entered on a cell. The delegate creates the widget as editing is started, and deletes the widget when editing is finished. When the cell is not being edited, the delegate is responsible for the static display of the data. The default delegate is very basic, edits with a QLineEdit and displays the Qt::DisplayRole. You do not need to keep track of editing widgets between edits.

    You can supply a delegate that does different things for different data types, indexes in a model, columns or rows in a view, or edits one item dependent on other items etc. Your custom delegate can display the data any way it sees fit when it is not being edited, including faking the appearance of the editing widget.

Similar Threads

  1. QStandardItemModel with QIdentityProxyModel
    By yagabey in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2014, 23:50
  2. Replies: 5
    Last Post: 18th November 2011, 23:12
  3. using QStandardItemModel
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 6th March 2011, 09:13
  4. QTreeView with QStandardItemModel
    By aekilic in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 09:11
  5. QStandardItemModel Help
    By frenk_castle in forum Newbie
    Replies: 1
    Last Post: 16th January 2010, 17:54

Tags for this Thread

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.