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

QStyledItemDelegate and index.isValid() assert

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 6.5.2
    • Widgets: Itemviews
    • None
    • Windows

    Description

      In QStyleItemDelegate on line 367 you have assert for invalid index. Maybe it's needed.

      But I have a following use case:

      void
      WordWrapItemDelegate::paint( QPainter * painter,
          const QStyleOptionViewItem & option, const QModelIndex & index ) const
      {
          QStyledItemDelegate::paint( painter, option, QModelIndex() ); 
      
          painter->drawText( option.rect,
              Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter,
              index.data( Qt::DisplayRole ).toString() );
      } 

      As you can see I draw everything with QStyledItemDelegate, but text I draw manually. To draw everything without data I pass QModelIndex() to QStyledItemDelegate:paint(). And in debug build this leads to assert dialog.

      Could you clarify your opinion to dissallow invoke paint() method with invalid index in QStyledItemDelegate?

      My use case, as I guess, is very common...

      Attachments

        1. assert.png
          assert.png
          11 kB
        2. main.cpp
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            igor.mironchik Igor Mironchik
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes