PDA

View Full Version : Can't move Items in the scene



maverick_pol
16th May 2008, 08:59
Hi guys,

I have a custom scene, implemented virtual methods:


void drawBackground..
void drawForeground..
void mouseMoveEvent ..
void mousePressEvent..
void keyPressEvent ..
void keyReleaseEvent..
void contextMenuEvent..

Here my view/scene settings


m_scene->setItemIndexMethod(QGraphicsScene::NoIndex);
m_scene->setSceneRect(QRectF(QPointF(-180,-90),QPointF(180,90)));
...
m_view->setCacheMode(QGraphicsView::CacheBackground);
m_view->setOptimizationFlag(QGraphicsView::DontClipPainter );
m_view->setOptimizationFlag(QGraphicsView::DontSavePainter State);
m_view->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);
m_view->setRenderHints( QPainter::HighQualityAntialiasing);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
m_view->setScene(m_scene);
m_view->setSceneRect(QRectF(QPointF(-180,-90),QPointF(180,90)));
m_view->setBackgroundColor(m_colorMap.value("NODTA"));
m_view->show();

This is the item I create in the scene/view owner class:


QGraphicsEllipseItem* item = new QGraphicsEllipseItem(QRectF(0,0,20,20));
item->setPen(QPen(Qt::red));
item->setBrush(QBrush(Qt::red));
item->setFlag(QGraphicsItem::ItemIsMovable);
item->setVisible(true);
m_scene->addItem(item);

The ellipse is shown, can be selected(if I turn the flag on), but I can't move the item? The question is why?

Thanks.

Kacper

wysota
16th May 2008, 09:26
You have to call the base class implementation of mousePressEvent and mouseMoveEvent for the scene.

maverick_pol
16th May 2008, 09:40
Thanks.

I also found some related topics, useful if someone search the forum and get this thread:
http://www.qtcentre.org/forum/f-qt-programming-2/t-graphics-view-event-propagation-8501.html
http://www.qtcentre.org/forum/f-qt-programming-2/t-qgraphicsitem-qgraphicsscene-8396.html
http://www.qtcentre.org/forum/f-qt-programming-2/t-qgraphicsitem-qgraphicsscene-8396.html

Kacper