Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractItemModel: no flagsChanged( const QModelIndex& index ) notification signal

QAbstractItemModel: no flagsChanged( const QModelIndex& index ) notification signal

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • napajejenunedk0N Offline
    napajejenunedk0N Offline
    napajejenunedk0
    wrote on last edited by
    #1

    What functionality QAbstractItemModel offers:

    data:

    setter: setData
    getter: data
    notifier: dataChanged

    flags:

    getter: itemFlags

    The only way to tell model's views to lookup the flags on demand and apply them both visually and functionally is to fire rowsRemoved + rowsInserted or modelReset. Emitting dataChanged makes the views reapply the model's flags at the given QModelIndex-es only functionally but not visually. So, let's suppose that the enablence of an item at a given QModelIndex depends on the value of the Qt::CheckStateRole of the same item (for instance) - checked = enabled, unchecked = disabled. Unchecking the checkbox at that QModelIndex and firing only dataChanged at that index will make the item functionally disabled but will retain its visual state - the same as it was when the item was enabled.

    What I think is that there should be at least flagsChanged signal without setter, so that it is possible to notify the views that flags have changed.

    Does anyone knows how to notify flags changed in a more correct manner, so that views refresh their visual state as well?

    (duplicate topic: http://qt-project.org/forums/viewthread/18504)

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      bq. So, let’s suppose that the enablence of an item at a given QModelIndex depends on the value of the Qt::CheckStateRole of the same item

      imho this should be wrong, the enablance of an item(and in general its functionality) depends on the flags, only, in this case on Qt::ItemIsEnabled ... it does not depend on Qt::CheckStateRole which controls exactly the visual box checking by item's internal check states; so no enabling/disabling code by changing flags should be put in setData()for this role! rather the same code used in setData() for changing check states must be used in flags() to combine flags

      1 Reply Last reply
      0
      • napajejenunedk0N Offline
        napajejenunedk0N Offline
        napajejenunedk0
        wrote on last edited by
        #3

        Probably, I haven't explained the example scenario correctly.
        Let's suppose that we have a table that lists countries you have visited. The table would have two columns:

        1. country name + checkbox to denote if you have visited the country
        2. the number of visits - editable, so that you could set the times you have visited the given country. The requirement here is that this table cell should be disabled if the cbeckbox of column 1 is unchecked and enabled if the checkbox is checked.

        How would you acbieve this behavior?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved