Details
-
Suggestion
-
Resolution: Out of scope
-
P4: Low
-
None
-
None
-
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); }