Hello,
I upgraded from Qt 4.8 to 5.4 and I noticed odd behaviors of my gui application. I'm using the graphics view framework and my setup is the standard items in a scene in a graphics view layout. The first thing I noticed is that my QGraphicsRectItems are now suddenly huge compared to before. I use the setRect() method in the constructor to define the size like so:
{
setRect(-0.05, -0.035, 0.1, 0.07);
}
Foot::Foot(QGraphicsItem *parent)
: QGraphicsRectItem(parent)
{
setRect(-0.05, -0.035, 0.1, 0.07);
}
To copy to clipboard, switch view to plain text mode
It seems that now the setRect() methods add to the default size rather than replacing it, such that I have to subtract a unit rectangle to get the same size I intended before like so:
{
setRect(-0.05 +0.5, -0.035 +0.5, 0.1 -1, 0.07 -1);
}
Foot::Foot(QGraphicsItem *parent)
: QGraphicsRectItem(parent)
{
setRect(-0.05 +0.5, -0.035 +0.5, 0.1 -1, 0.07 -1);
}
To copy to clipboard, switch view to plain text mode
Is this intended behavior or a bug?
The second thing I noticed is that the item discovery seems to be broken. The attached screenshot Screenshot from 2015-04-22 14:58:11.jpg was produced by the following code in my graphics view:
void GraphicsViewWidget
::drawForeground(QPainter* painter,
const QRectF
& rect
) {
painter->resetTransform(); // The painter draws in scene coordinates by default. We want draw in view coordinates.
// Item detector.
for (int i = 0; i < width(); i+=5)
{
for (int j = 0; j < width(); j+=5)
{
int itemCount = sc->items(mapToScene(i,j)).size();
if (itemCount > 0)
painter->drawEllipse(i, j, itemCount, itemCount);
}
}
}
class GraphicsViewWidget : public QGraphicsView {...}
void GraphicsViewWidget::drawForeground(QPainter* painter, const QRectF& rect)
{
painter->resetTransform(); // The painter draws in scene coordinates by default. We want draw in view coordinates.
// Item detector.
QGraphicsScene* sc = scene();
for (int i = 0; i < width(); i+=5)
{
for (int j = 0; j < width(); j+=5)
{
int itemCount = sc->items(mapToScene(i,j)).size();
if (itemCount > 0)
painter->drawEllipse(i, j, itemCount, itemCount);
}
}
}
To copy to clipboard, switch view to plain text mode
The above code draws a dot at the view coordinates where at least one item was found in the scene. All items in the scene are covered by dots, but also a lot of places where there are no items. When I use the QGraphicsView::items() method, the item discovery works perfectly. QGraphicsScene::items() seems to be broken, however, and it has implications to the UI. The dotted areas respond to the mouse and the scene / the items believe that the mouse is on the item, which is not true. To me this clearly looks like a bug, but in any case, what can I do to fix this?
Cheers,
Cruz
Bookmarks