PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 962 - Incorrect rectangle of active area for interactive selection and move for QGraphicsRectItem
: Incorrect rectangle of active area for interactive selection and move for QGr...
Status: CLOSED INVALID
Product: PySide
Classification: Unclassified
Component: QtGui
: 1.0.5
: PC MS Windows XP/Vista/7
: P3 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-08-07 18:34 EEST by esp.home
Modified: 2011-10-08 12:07 EEST (History)
8 users (show)

See Also:


Attachments
Test python script for show bug (630 bytes, text/plain)
2011-08-07 18:34 EEST, esp.home
Details
Test python script for show bug (580 bytes, text/plain)
2011-08-07 19:01 EEST, esp.home
Details
C++ version, works exactly like Python version on 64 bits systems (664 bytes, text/x-c++src)
2011-08-17 20:40 EEST, Hugo Parente Lima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description esp.home 2011-08-07 18:34:05 EEST
Created attachment 390 [details]
Test python script for show bug

If you set flags "QGraphicsItem.ItemIsSelectable" or
"QGraphicsItem.ItemIsMovable" for QGraphicsRectItem, rectangle of active area
will be a incorrect. TopLeft point of active rect will be a begin in item rect
TopLeft - 1.

For example:
...
item_rect = QGraphicsRectItem()
item_rect.setRect(10, 10, 100, 100)
item_rect.setFlag(QGraphicsItem.ItemIsSelectable, True)

scene.addItem(item_rect)
...

Rect of active area for item selection will be: [ x=9, y=9, w=101, h=101 ] in
scene coordinates.
At the same time, methods boundingRect() and shape() return the correct values.

In PyQt4 this bug is not exist.
Comment 1 esp.home 2011-08-07 19:01:51 EEST
Created attachment 391 [details]
Test python script for show bug
Comment 2 Hugo Parente Lima 2011-08-17 01:16:22 EEST
It behaves exactly the same here with PyQt/py3k and PySide.

Would you write some code that asserts on fail to show de bug?
Comment 3 esp.home 2011-08-17 08:57:19 EEST
(In reply to comment #2)
> It behaves exactly the same here with PyQt/py3k and PySide.

I decided to check the behavior on the Linux x64 platform and the following
configuration:
Python: 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) x64
PyQt4: 4.8.3-2
PySide: 1.0.1

Behavior between PySide and PyQt4 is equal and incorrectly.

At the same time on Windows platform and the following configuration:
Python: 2.7 x86
PyQt4: 4.8.1
PySide: 1.0.5

PyQt4 working correctly, but incorrectly PySide.

I also want to check this behavior on the Qt C++, and write a test code.


PS:
I would not pay any attention to it, but this behavior is actually a hindrance. 
I can not properly manage graphical items on the scene, because of their active
areas overlap each other.
Comment 4 Hugo Parente Lima 2011-08-17 20:24:38 EEST
QGraphicsView uses floating point coordinates, so I guess your bug is
reproducible on C++ as well due to the fact that it's caused by rounding
problem when converting numbers from int to float/double.

I'll write your example in C++ to check my theory.
Comment 5 Hugo Parente Lima 2011-08-17 20:40:23 EEST
Created attachment 403 [details]
C++ version, works exactly like Python version on 64 bits systems

The same behavior occur on C++, so it's really a Qt problem, probably caused by
floating point vs integers.
Comment 6 renato filho 2011-08-23 00:37:18 EEST
Release PySide 1.0.6
Comment 7 esp.home 2011-10-08 12:07:23 EEST
I found where the problem is.

Problem in Qt source-file qgraphicsscene.cpp in method itemsAtPosition.

/*!
    Returns all items for the screen position in \a event.
*/
QList<QGraphicsItem *> QGraphicsScenePrivate::itemsAtPosition(const QPoint
&/*screenPos*/,
                                                              const QPointF
&scenePos,
                                                              QWidget *widget)
const
{
    Q_Q(const QGraphicsScene);
    QGraphicsView *view = widget ? qobject_cast<QGraphicsView
*>(widget->parentWidget()) : 0;
    if (!view)
        return q->items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder,
QTransform());

    const QRectF pointRect(scenePos, QSizeF(1, 1));
    if (!view->isTransformed())
        return q->items(pointRect, Qt::IntersectsItemShape,
Qt::DescendingOrder);

    const QTransform viewTransform = view->viewportTransform();
    return q->items(pointRect, Qt::IntersectsItemShape,
                    Qt::DescendingOrder, viewTransform);
}


Line:
const QRectF pointRect(scenePos, QSizeF(1, 1));

Always checked for intersection with the rectangle 1x1. If position point left
and above on <= 1, function "items" return items.

This is bad.