Results 1 to 5 of 5

Thread: disable a parent and children in a tree model

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default disable a parent and children in a tree model

    working with editable tree model in the examples
    I want to disable certain branches when the user selects certain options in the interface.

    Should this be done by setting the flags of the parent of a branch to disable, using Qt::ItemIsEnabled?

    How can I do that?
    thanks

  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: disable a parent and children in a tree model

    Yes, you have to return proper flags from your flags() implementation.
    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
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: disable a parent and children in a tree model

    sorry, I am not being clear. There is no implementation example of "setflags()" or something. The implemebntation of flags in the editabletreemodel example is

    Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
    {
    [...]
    }
    I don't understand when this is called. It seems to be done automatically when the treemodel is viewed? How can I set a flag of an item at a given index?
    thanks

  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: disable a parent and children in a tree model

    You don't set a flag, you return flags whenever someone asks for them. When the model tells the environment that a particular index has changed its data, all the views will probably re-ask for the flags so at this point you may return something different than before.

    Qt Code:
    1. Qt::ItemFlags MyModel::flags(...) const {
    2. Qt::ItemFlags defFlags = BaseClass::flags(index);
    3. if(shouldBeDisabled(index))
    4. defFlags &= ~Qt::ItemIsEnabled;
    5. return defFlags;
    6. };
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: disable a parent and children in a tree model

    thanks, that got me further. Disabling a parent does not disable the children. After some trying my solution is as follows: when a certain branch has to be disabled I take the row of the parent of that branch, and in flags the only line to be added is:
    if (index.row() == rowdisable|| index.parent().row() == rowdisable)
    flags &= ~Qt::ItemIsEnabled;

    rowdisable is an integer and member of the treemodel

Similar Threads

  1. Replies: 6
    Last Post: 8th July 2009, 14:24
  2. Replies: 1
    Last Post: 7th July 2009, 08:13
  3. Replies: 4
    Last Post: 1st May 2009, 12:00
  4. Replies: 2
    Last Post: 19th August 2008, 10:46
  5. Replies: 3
    Last Post: 29th May 2008, 14:50

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.