I'm placing my items using setPos
//------------------------------------------------------------------------------
void WorldGraphicsScene
::loadSection(QString section,
int x,
int y,
int width
) {
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
QFileInfo file("resources/world/" + section
+ "/" + section
+ "_" + QVariant(i
).
toString() + "_" + QVariant(j
).
toString() + ".jpg");
ImageItem* image = new ImageItem(file);
image->setPos(x + (i * width), y + (j * width));
image->setEnabled(false);
image->setDrawBorder(false);
this->addItem(image);
}
}
}
//------------------------------------------------------------------------------
void WorldGraphicsScene::loadSection(QString section, int x, int y, int width)
{
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
QFileInfo file("resources/world/" + section + "/"
+ section + "_" + QVariant(i).toString()
+ "_" + QVariant(j).toString() + ".jpg");
ImageItem* image = new ImageItem(file);
image->setPos(x + (i * width), y + (j * width));
image->setEnabled(false);
image->setDrawBorder(false);
this->addItem(image);
}
}
}
To copy to clipboard, switch view to plain text mode
My boundingRect looks like this:
//------------------------------------------------------------------------------
QRectF BaseItem
::boundingRect() const {
return QRectF(0,
0, Settings
::ImageWidth, Settings
::ImageWidth);
}
//------------------------------------------------------------------------------
QRectF BaseItem::boundingRect() const
{
return QRectF(0, 0, Settings::ImageWidth, Settings::ImageWidth);
}
To copy to clipboard, switch view to plain text mode
Do I need to implement the shape method too?
And here my simplified drawing code:
//------------------------------------------------------------------------------
{
QRectF bounds
= boundingRect
();
painter->drawPixmap(bounds, _image);
}
//------------------------------------------------------------------------------
void ImageItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0*/)
{
QRectF bounds = boundingRect();
painter->drawPixmap(bounds, _image);
}
To copy to clipboard, switch view to plain text mode
I didn't account the pen width since I don't use a pen/outline. Do I have to?
Bookmarks