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

Support cosmetic pens in QGraphicsItem

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: P4: Low
    • Resolution: Out of scope
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
      None

      Description

      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);
      }
      

        Attachments

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

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes