Crazy over the QGraphicsScene/Item
I have added an customized QGraphicsPixmapItem to the Scene, but when I click on the item.. what can I say, it records it as a ordinary click on the scene, but if I click more than once very quickly, it also notice that the item is clicked.
(as a side note: if I click exactly in the left margin of the Item, it seems to respond to a slow single click.)
It's driving me crazy. :crying: :eek: :confused:
Here is code for the item
Code:
{
Qt::MouseButtons btn = ev->buttons();
if (btn & Qt::LeftButton)
{
qDebug()<<"You visited Lamerville";
}
}
When I set the position for the item, I set it with integer coordinats. but I think that can hardly be the problem.
Here is code for the scene
Code:
{
QPointF p
= ev
->buttonDownScenePos
( Qt
::LeftButton);
int x,y;
x=p.x()/SKAL;
y=p.y()/SKAL;
qDebug()<<"you pressed mouse on map"<<x<<y;
SKAL is a constant for scaling purposes.
I'd be very happy for any suggestion. I guess there is a fundamental flaw... but what is it? :confused:
Re: Crazy over the QGraphicsScene/Item
Did u subclass the pix item ??
if yes, while handling mousepress event.. try passing it to QGraphicsItem::mousePressEvent ()....
also how are town and game related ??
Re: Crazy over the QGraphicsScene/Item
Yes I did this:
Code:
public:
protected:
};
In the town.cpp file I have
Code:
{
Qt::MouseButtons btn = ev->buttons();
if (btn & Qt::LeftButton)
{
qDebug()<<"You visited Lamerville";
}
}
Should I add a line
to the code? Where? In the beginning of the function?
Exactly, what will it accomplish?
town and game is related by populating the game ( a Scene) with towns (Items)
Code:
QVector<QPoint> cities = map->randomTownPositions(8);
Town* t;
foreach (pos, cities)
{
t = new Town(pos);
addItem(t);
towns.push_back(t);
}
I think the "additem" will be enough, won't it?
Re: Crazy over the QGraphicsScene/Item
did u try adding QGraphicsItem::mousePressEvent () to ur mousepressevent ??
Re: Crazy over the QGraphicsScene/Item
Sorry, I did something to solve it. I can't remember right now.
But I think it was somethign with mousPressEvent.. or.. no. I don't remember what it was.
Re: Crazy over the QGraphicsScene/Item
well.. if u remmeber what u did.. u may post it.. it may benefit me too if ur way is not known :)
Re: Crazy over the QGraphicsScene/Item
I think it was something with adding the item to the scene or setting the parent.