PDA

View Full Version : Selection precision problems with QGraphicsScene and scaled content?



dropkickz
13th February 2012, 20:08
Hi,

I got precision problems with the selection in a QGraphicsScene. It is quiet simple to reproduce. Here is my code...



//----------------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------------

#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QHBoxLayout>

//----------------------------------------------------------------------------

class MyFooView : public QGraphicsView
{
public:
MyFooView(QWidget* parent = NULL) :
QGraphicsView(parent)
{
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
MyFooView(QGraphicsScene* scene, QWidget* parent = NULL) :
QGraphicsView(scene, parent)
{
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
scale(20.0, 20.0);
}
~MyFooView(void)
{
}
};

int main(int argv, char **args)
{
QApplication app(argv, args);

QGraphicsScene* scene = new QGraphicsScene();
scene->setSceneRect(QRectF(0, 0, 5000, 5000));

MyFooView* view = new MyFooView(scene);

QGraphicsRectItem* dummy = new QGraphicsRectItem(50.0, 50.0, 30.0, 30.0);
dummy->setBrush(QBrush(Qt::red));
dummy->setAcceptHoverEvents(true);
dummy->setFlag(QGraphicsItem::ItemIsSelectable, true);
dummy->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
scene->addItem(dummy);

view->centerOn(0.0, 0.0);

QHBoxLayout* l = new QHBoxLayout;
l->addWidget(view);

QWidget* w = new QWidget();
w->setLayout(l);
w->show();

return app.exec();
}


Run the program. For me it is possible to select the rect item a bit above and left of its shape. Can someone confirm and tell me how to solve it?

Best regards,
Marcus

steno
14th February 2012, 16:11
The problem you are seeing could be related to this bug.

https://bugreports.qt-project.org/browse/QTBUG-17985

dropkickz
16th February 2012, 15:26
The problem you are seeing could be related to this bug.

https://bugreports.qt-project.org/browse/QTBUG-17985
Thanks a lot. With the proposed fix everything works as expected!