Yes I did this:
public:
protected:
};
class Town :public QGraphicsPixmapItem {
public:
Town(QPoint p=QPoint(0,0));
void mousePressEvent(QGraphicsSceneMouseEvent* ev);
protected:
QString name;
};
To copy to clipboard, switch view to plain text mode
In the town.cpp file I have
{
Qt::MouseButtons btn = ev->buttons();
if (btn & Qt::LeftButton)
{
qDebug()<<"You visited Lamerville";
}
void Town::mousePressEvent(QGraphicsSceneMouseEvent* ev)
{
Qt::MouseButtons btn = ev->buttons();
if (btn & Qt::LeftButton)
{
qDebug()<<"You visited Lamerville";
}
To copy to clipboard, switch view to plain text mode
}
Should I add a line
QGraphicsItem::mousePressEvent ();
To copy to clipboard, switch view to plain text mode
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)
QVector<QPoint> cities = map->randomTownPositions(8);
Town* t;
foreach (pos, cities)
{
t = new Town(pos);
addItem(t);
towns.push_back(t);
}
QVector<QPoint> cities = map->randomTownPositions(8);
QPoint pos;
Town* t;
foreach (pos, cities)
{
t = new Town(pos);
addItem(t);
towns.push_back(t);
}
To copy to clipboard, switch view to plain text mode
I think the "additem" will be enough, won't it?
Bookmarks