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

Wrong documentation for Qt::ItemDataRole expected types

    XMLWordPrintable

Details

    • 6880b7c39b (qt/qtbase/dev) a591865844 (qt/qtbase/6.3) 35a09fc7e9 (qt/qtbase/6.2) 35a09fc7e9 (qt/tqtc-qtbase/6.2) a591865844 (qt/tqtc-qtbase/6.3) 6880b7c39b (qt/tqtc-qtbase/dev)

    Description

      The documentation for the built-in roles say that certain dataypes are expected to be returned from the model:

      https://doc.qt.io/qt-5/qt.html#ItemDataRole-enum

      Qt::TextAlignmentRole The alignment of the text for items rendered with the default delegate. (Qt::Alignment)

      However, actually returning some of those datatypes does not work. For instance for Qt::TextAlignmentRole one actually has to return an int. The reason boils down to the default delegate using an int:

      https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp.html#287

          value = index.data(Qt::TextAlignmentRole);
          if (value.isValid() && !value.isNull())
      option->displayAlignment = Qt::Alignment(value.toInt());
      

      This is very related to having an automatic QFlags to int conversion performed by QVariant (see QTBUG-74639 and friends). If anything, the documentation has to be amended, and I'd really like to have the feature in QVariant itself so one can return the real datatype and not int.

      Attachments

        Issue Links

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

          Activity

            People

              dfaure_kdab David Faure
              peppe Giuseppe D'Angelo
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: