Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-25224

Overriding data() in subclass of QStandardItem makes setFlags() not working

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • 5.15, 6.6
    • 4.7.4, 4.8.0
    • GUI: Look'n'Feel
    • None
    • VirtualBox - Debian sid, g++ 4.6.3, Eclipse CTD 4

    Description

      Hello! Today I've run into a problem. (example code is included in attachment)

      When I've subclassed QStandardItem and impelemented my own data() function:

      QVariant CollectionItem::data(int role) const
      {
       switch(role)
       {
        /*
      custom roles
      */
       
        default:
         return QVariant();
       }
      }
      {quote}
      I've encountered this bug:
      {quote}
      CollectionItem* item = new CollectionItem("Your collection is empty! Visit settings", "", "", 0, false);
      qDebug() << item->flags();
       item->setFlags(0);
       qDebug() << item->flags();
       appendRow(item);
       
       QStandardItem *i = new QStandardItem();
       qDebug() << i->flags();
       i->setFlags(0);
       qDebug() << i->flags();
      

      Output:

      QFlags(0x1|0x2|0x4|0x8|0x20)
      QFlags(0x1|0x2|0x4|0x8|0x20)
      QFlags(0x1|0x2|0x4|0x8|0x20)
      QFlags()
      

      After some research I've managed to fix this bug by changing data() to

      default:
          return QStandardItem::data(role);
      

      Instead of returning empty QVariant().

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            mattrick Kacper Banasik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes