Results 1 to 6 of 6

Thread: TreeView ->"read only" [TreeModelCompleter Tutorial]

  1. #1
    Join Date
    May 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default TreeView ->"read only" [TreeModelCompleter Tutorial]

    Hi all,
    I played a little bit around with the tutorials and I wondered how to set the TreeView from the TreeModelCompleter as read only...

    Some kind of:
    Qt Code:
    1. ~Qt::ItemIsEditable
    To copy to clipboard, switch view to plain text mode 
    ...

    If I try to overwrite the
    Qt Code:
    1. Qt::ItemFlags
    To copy to clipboard, switch view to plain text mode 

    I get an error, because I can't have a multiple Inheritance with QObject.

    I hope you can help me to understand that!
    best Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TreeView ->"read only" [TreeModelCompleter Tutorial]

    How does your code look like when you get that error?

    Cheers,
    _

  3. #3
    Join Date
    May 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TreeView ->"read only" [TreeModelCompleter Tutorial]

    Hi,
    first of all thank you very much for your fast response!
    My idea was to insert a code like this:
    Qt Code:
    1. Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex& index) const
    2. {
    3. return (QStandardItemModel::flags(index) & ~Qt::ItemIsEditable);
    4. }
    To copy to clipboard, switch view to plain text mode 

    If I do this I get an error as the following: C2352: 'QStandardItemModel::flags' illegal call of non-static member function.
    I don't know how to add QAbstractItemModel to my class, because I've already added another subclass of QObject.
    Do you have an hint for me?

    Is there any other opportunity to make the TreeModelCompleter Example not editable?
    best regards

  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: TreeView ->"read only" [TreeModelCompleter Tutorial]

    What class does MyStandardItemModel inherit from?

    If you want the view to disallow editing on the model (regardless of the model's editability) then you can
    Qt Code:
    1. view->setEditTriggers(QAbstractItemView::NoEditTriggers);
    To copy to clipboard, switch view to plain text mode 

    If you want the model to be read only everywhere then you use QAbstractItemModel::flags() to indicate that.

  5. The following user says thank you to ChrisW67 for this useful post:

    Concept2 (20th May 2014)

  6. #5
    Join Date
    May 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: TreeView ->"read only" [TreeModelCompleter Tutorial]

    My Code is very similar to the TreeModelCompleter. The only change I made is, that I swapped the modelFromFile() -function from the mainwindow class to the treemodelcompleter class. Right now, I want to set this standard treeview as "read only"
    To answer your question, this class inherits from QCompleter.

    Thanks


    Added after 1 18 minutes:


    Thank you very much for your help! I think the first option works fine for me but nevertheless I would be very interested in how to implement the second option.
    best regards
    C
    Last edited by Concept2; 20th May 2014 at 10:16.

  7. #6
    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: TreeView ->"read only" [TreeModelCompleter Tutorial]

    ModelFromFile() builds a QAbstractItmModel subclass not a QCompleter subclass. It is that model that needs to return flags() that do not allow editing. In the example you could simply call setEditable() on each QStandardItem as it was added to the model.

Similar Threads

  1. Replies: 4
    Last Post: 2nd June 2012, 07:04
  2. Replies: 11
    Last Post: 21st June 2011, 01:05
  3. Replies: 6
    Last Post: 16th June 2011, 13:20
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. Replies: 1
    Last Post: 18th August 2006, 13:41

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.