Results 1 to 5 of 5

Thread: Flags of a list model

  1. #1
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Flags of a list model

    Hi there

    I've got a list model that is derived from QAbstractListModel. There I try to set the flags:
    Qt Code:
    1. Qt::ItemFlags MembersListModel::flags(const QModelIndex& index) const {
    2. if(index.isValid())
    3. return Qt::ItemIsEnabled;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Later I want to set different flags for different kinds of items.

    But somehow this is not working at all. All the items are selectable and checkable (with a checkbox).
    What am I doing wrong? Could it be that I missed something in the delegate?

    Thx Luke
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  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: Flags of a list model

    Does the declaration of your flags method contain a QModelIndex() as the default argument for the index parameter?
    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
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Flags of a list model

    No it doesn't.
    The declaration looks like this:
    Qt Code:
    1. virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
    To copy to clipboard, switch view to plain text mode 

    I suppose there shouldn't be a default argument. There is none in the base class. And it not working either with the default argument;
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  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: Flags of a list model

    Quote Originally Posted by woodtluk View Post
    No it doesn't.
    I suppose there shouldn't be a default argument. There is none in the base class. And it not working either with the default argument;
    Eeem, sorry, my fault, I got carried away. Default argument should be only for the parent arguments. Check if you have those everywhere.

    As for your problem, check if your method is called at all, it probably isn't.

    As for the checkable problem, it is likely your data() method is incorrect. You are probably not retuning an invalid QVariant for Qt::CheckStateRole.
    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
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Flags of a list model

    Thanks!

    I didn't handle the Qt::CheckStateRole in the data() method.

    There is still a topic with the selection. But I think it's a similar thing in the delegate..

    cheers Luke
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

Similar Threads

  1. Does QDataWidgetMapper use flags?
    By Netwiz in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2021, 00:56
  2. remove flags?
    By konvex in forum Qt Programming
    Replies: 5
    Last Post: 18th March 2015, 02:26
  3. How to map tree model data to list view
    By msopanen in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 19:56
  4. Flags not doing the work
    By chaosgeorge in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2006, 23:35
  5. [QT4.1.1 XP] multi-columns list model/view
    By incapacitant in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 13:38

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.