PDA

View Full Version : QGraphicsView/Item Tiling Problem



tomf
26th August 2008, 10:23
Hi,
I'm trying to display the map of the world using graphics items with the graphics view. Since my world map consists of many images I'm getting some wired "grid lines" between the items which shouldn't be there. All my items coordinates are next to each other.

I have attached a picture of what I mean.

Antialiasing is disabled, and I also tried to set the QGraphicsView::DontAdjustForAntialiasing flag - without success.

Any ideas?

salmanmanekia
26th August 2008, 10:41
All my items coordinates are next to each other.
have you set the coordinates using setPos() or something else..

aamer4yu
26th August 2008, 10:53
Did u account for pen width drawing, in boundingRect() ??
How are u placing the items and what have u done in boundingRect() , shape() functions ?

tomf
26th August 2008, 11:22
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);
}
}
}


My boundingRect looks like this:


//------------------------------------------------------------------------------
QRectF BaseItem::boundingRect() const
{
return QRectF(0, 0, Settings::ImageWidth, Settings::ImageWidth);
}


Do I need to implement the shape method too?

And here my simplified drawing code:


//------------------------------------------------------------------------------
void ImageItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0*/)
{
QRectF bounds = boundingRect();
painter->drawPixmap(bounds, _image);
}


I didn't account the pen width since I don't use a pen/outline. Do I have to?

tomf
29th August 2008, 09:58
nobody?

I also encountered an other problem: I'm using a QGraphicsView in a QStackedWidget as my centralwidget in a QMainwindow. Now I noticed that the bigger the window gets the slower my application gets. First I thought thats because there is more to display - but there isn't. I'm showing the exact same thing (couple pictures which can freely be moved and zoomed). If my window size is lets say 640x480 and I'm displaying 20 pictures its much faster than if my window is 1280x1024 and I'm displaying 20 pictures (in the exact same zoom level). Am I doing something wrong?