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

Wrong documentation for Qt::ItemDataRole expected types

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.9.7, 5.12.2
    • Fix Version/s: None
    • Labels:
      None

      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

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

          Activity

            People

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

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes