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

Support cosmetic pens in QGraphicsItem

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Out of scope
    • Icon: P4: Low P4: Low
    • None
    • None
    • Widgets: GraphicsView
    • None

      QGraphicsItem doesn't currently support use of cosmetic pens. If you do use cosmetic pens, the item is likely to not update correctly unless you enable QGraphicsView::FullViewportUpdate.

      This task suggests that we add support for it.

      The reason why it's not currently supported is that the item's coordinate system is defined in logical space, whereas cosmetic pens' geometry are defined in device space. Up until Qt 4.4, the items' bounding rect are mapped to the scene, then to each respective view. Since Qt 4.5, the bounding rects are mapped directly to the view, which means that the item can adjust this mapping in device space.

      One way to solve the issue is to add viewport / pixel margins to the item, as a property:

      void QGraphicsItem::getPixelMargins(int *left, int *top, int *right, int *bottom)
      {
           *left = 1;
           *right = 1;
           *top = 1;
           *bottom = 1;
      }
      
      void MyGraphicsItem::paint(...)
      {
          QPen pen(Qt::blue, 2);
          pen.setCosmetic(true);
          painter->setPen(pen);
          painter->drawRect(rect);
      }
      

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

            Unassigned Unassigned
            hanssen Andreas Aardal Hanssen (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes