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

Misleading wording regarding the return value of itemChanged

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.2.1
    • Documentation
    • None

    Description

      I answered a question on StackOverflow that ended up being the result of not calling the default method in itemChanged(). The person asking the question had a handler that looked like:

      QVariant Vertice::itemChange(GraphicsItemChange change, const QVariant & value)
      {
          switch(change) {
              case QGraphicsItem::ItemSelectedHasChanged:
                  qWarning() << "vertex: " + value.toString(); // never happened
                  break;
      
              default:
                  break;
          }
      }
      

      When the ItemFlagsChange notification was received, this returned nothing. You are usually supposed to call the base method QGraphicsItem::itemChange(change, value). I pointed out the reason for the problem to answer the question.

      In response, they mentioned disappointment that the Qt documentation for QGraphicsItem::ItemSelectedHasChanged says: "The item's selected state has changed. The value argument is the new selected state (i.e., true or false). Do not call setSelected() in itemChange() as this notification is delivered. The return value is ignored."

      I'm in agreement that saying "The return value is ignored" is probably the wrong emphasis. I would reword to say something like "the return value should always be the base class QGraphicsItem::itemChange(change,value) - as returning a different result cannot affect the operation."

      If that section were rewritten to generally emphasize this point, I suspect there would be fewer troubles of this kind.

      See: http://stackoverflow.com/questions/21745025/

      Attachments

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

        Activity

          People

            vertries Nico Vertriest (Inactive)
            hostilefork Brian Dickens
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes