[Qt-interest] Malfunctioning QGraphicsItem::ItemIsMovable?
Stephen Chu
stephen at ju-ju.com
Wed Apr 27 16:11:35 CEST 2011
You probably run into this bug:
<http://bugreports.qt.nokia.com/browse/QTBUG-17985>
And I submitted a merge request for it:
<http://bugreports.qt.nokia.com/browse/QTBUG-17985>
So far it's only been reviewed on the formatting of the code, not the
fix itself. :(
In article <BANLkTi=fAHhEzB8M4banSkQTKz8eHy+Rzw at mail.gmail.com>,
Sherif Ghali <sherif.ghali.1 at gmail.com> wrote:
> It occasionally seems that the index of QGraphicsScene is not
> right. The code below demonstrates one case. If I drag the red,
> green, or blue node, another node will move instead. If I replace
> '-0.05' with '-0.5', dragging works normally.
>
> // MyGraphicsScene.h
> #include <QtGui>
>
> class MyGraphicsScene : public QGraphicsScene
> {
> Q_OBJECT
> public:
> MyGraphicsScene()
> {
> setSceneRect(QRectF(QPointF(-2,-2), QSizeF(4,4)));
> setBackgroundBrush(Qt::black);
>
> insert_node( QPointF( -0.05,-0.05), Qt::red );
> insert_node( QPointF( 1,-0.05), Qt::green );
> insert_node( QPointF( -0.05,1), Qt::blue );
> insert_node( QPointF( 1,1), Qt::yellow );
> }
> private:
> QGraphicsEllipseItem * insert_node(const QPointF & p, const QColor &
> color)
> {
> const QRectF n(QPointF(-0.1,-0.1), QSizeF(0.2,0.2));
> QGraphicsEllipseItem * node = new QGraphicsEllipseItem( n );
> node->setPen(color);
> node->setBrush(color);
> node->setFlags(QGraphicsItem::ItemIsMovable);
> node->setPos(p);
> addItem(node);
> return node;
> }
> };
>
> // main.cpp
> #include "MyGraphicsScene.h"
> #include <QtGui>
>
> int main(int argc, char * argv[])
> {
> QApplication app(argc, argv);
> MyGraphicsScene * scene = new MyGraphicsScene;
> QGraphicsView * view = new QGraphicsView(scene);
> view->fitInView(scene->sceneRect() , Qt::KeepAspectRatio);
> view->setMinimumSize(QSize(640,480));
> view->show();
> return app.exec();
> }
--
Stephen Chu
More information about the Qt-interest-old
mailing list