PDA

View Full Version : Question about the MouseMoveEvent of qtdemo's TextButton



yzdying
19th February 2011, 02:59
When I was add "item->setFlags(QGraphicsItem::ItemIsMovable);" in menumanager.cpp

First, One can move to what the mouse move.But second time to move the item,it will jump to the Original pos of first time.

What the problem is ?

yzdying
21st February 2011, 12:17
Nobody know?

high_flyer
21st February 2011, 12:48
Speaking only for me, I just don't understand what you wrote.
Try to explain more in details, and add code.

yzdying
22nd February 2011, 02:14
Think you high_flyer, My English is no good,
I would like to use MouseMoveEvent event of Textbutton, so that I can drag the item to the specified location.
I add the flag "QGraphicsItem::ItemIsMovable" to item in menumanager.cpp




void MenuManager::createMenu(const QDomElement &category, BUTTON_TYPE type)
{
.........

// create normal menu button
QString label = currentNode.toElement().attribute("name");
item = new TextButton(label, TextButton::LEFT, type, this->window->scene, this->window->mainSceneRoot);
currentNode = currentNode.nextSibling();

item->setFlags(QGraphicsItem::ItemIsMovable);

.........
}


First, Drag a item to specified location . When I click the leftbutton and start to drag the item,it will jump to (0 ,0) before the mouse moving.

I drag dowm a item from the location of (59, 233) to the specified location of (59, 236);
drag item pos output:
QPointF(59, 233)
QPointF(0, 1)
QPointF(0, 2)
QPointF(0, 3)

As you can see, the moving graber jump from (59, 233) to (0, 1).

So I don't know what cause this result.

You can have a try to drag.

high_flyer
22nd February 2011, 10:26
Please provide the code that deals with the moving, and setting of coordinates.

yzdying
22nd February 2011, 13:06
void TextButton::mouseMoveEvent(QGraphicsSceneMouseEven t *event)
{
qDebug() << pos();
QGraphicsItem::mouseMoveEvent(event);
}
Only to add the pos output. and Nothing modited to the qtdemo source besides added the ItemIsMovoble flag;

the moving graber is in scene coordinates

high_flyer
22nd February 2011, 14:23
But where is the code that sets the position in your code?

yzdying
22nd February 2011, 15:22
Thanks again!


//TextButton.cpp
void TextButton::mouseMoveEvent(QGraphicsSceneMouseEven t *event)
{
qDebug() << pos();
QGraphicsItem::mouseMoveEvent(event);
}



menumanager.cpp
void MenuManager::createMenu(const QDomElement &category, BUTTON_TYPE type)
{
.........

// create normal menu button
QString label = currentNode.toElement().attribute("name");
item = new TextButton(label, TextButton::LEFT, type, this->window->scene, this->window->mainSceneRoot);
currentNode = currentNode.nextSibling();

item->setFlags(QGraphicsItem::ItemIsMovable); ///this line is my added

.........
}



Only modified two places in the source of qtdemo.
But course that the moving item jump from (59, 233) to (0, 1) in the procedure of qtdemo.