使用 QVector 创建图形磁贴(QCache 之前的基础知识)

Creating Graphics Tiles Using QVector(Basics Before QCache)

本文关键字:基础知识 QCache 创建 QVector 图形 使用      更新时间:2023-10-16

我正在尝试升级我的地震图查看器以使用磁贴图形渲染。我对这个过程非常陌生,但我尝试创建一个简单的例子如下。我需要使用 QVector 或 QCache(为了简单起见,我现在使用 QVector 的原因是为了节省内存和需要即时创建的瓷砖。我不完全确定你是否能够做我在下面尝试做的事情,但本质上它会创建一个位图数组,使它们成为项目,然后尝试将它们添加到场景中。该程序编译时有十二个错误,没有一个直接引用我在 mainWindow .cpp 中编写的代码。

错误要么是这个

C:\Qt\Qt5.9.1\5.9.1\mingw53_32\include\QtCore\qvector.h:713: error: 使用已删除的功能'QGraphicsPixmapItem& QGraphicsPixmapItem::operator=(const QGraphicsPixmapItem&(' with the 唯一改变的是错误的位置(不同的标题 文件(

或者这个

C:\Qt\Qt5.9.1\5.9.1\mingw53_32\include\QtWidgets\qgraphicsitem.h:861: error: 'QGraphicsPixmapItem::QGraphicsPixmapItem(const QGraphicsPixmapItem&(' is private Q_DISABLE_COPY(QGraphicsPixmapItem( 在 qgraphicsitem.h 头文件中

生成的代码由于头文件中弹出的这些错误而无法编译

int count;
QVector<QBitmap> BitmapArrayTiles;
QVector<QGraphicsPixmapItem> PixmapItemsArray;
QGraphicsPixmapItem currentItem;
QBitmap currentBitmap;
QGraphicsScene *scene = new QGraphicsScene();
for(count = 0; count < 4; count++)
{
currentBitmap = QBitmap(150,150);
QPainter Painter(&currentBitmap);
QPen Pen(Qt::black); // just to be explicit
Painter.setPen(Pen);
drawStuff(Painter);
BitmapArrayTiles.insert(0, currentBitmap);
currentItem.setPixmap(BitmapArrayTiles[count]);
PixmapItemsArray.insert(count, currentItem);
scene->addItem(&currentItem);
currentItem.mapToScene((count*150)+150, (count*150)+150);
}
ui->TileView->setScene(scene);
^

我没有手动更改头文件,所以我不完全确定为什么会出现这些错误。

使用指针和眼泪

int count;
QGraphicsScene *scene = new QGraphicsScene(0, 0, 150*4, 150*4);
QVector<QBitmap*> BitmapArrayTiles;
QVector<QGraphicsPixmapItem*> BitmapItemsArray;
QGraphicsPixmapItem* CurrentItem;
QBitmap *CurrentBitmap;
const QBitmap* CurrentBitmapConstPointer = CurrentBitmap;
for(count = 0; count < 4; count++)
{
CurrentBitmap = new QBitmap(150,150);
QPainter Painter(CurrentBitmap);
QPen Pen(Qt::black); // just to be explicit
Painter.setPen(Pen);
drawStuff(Painter);
BitmapArrayTiles.insert(count, CurrentBitmap);
CurrentItem = new QGraphicsPixmapItem(*BitmapArrayTiles[count]);
BitmapItemsArray.insert(count, CurrentItem);
//PixmapItemsArray.insert(count, currentItem);
scene->addItem(BitmapItemsArray[count]);
BitmapItemsArray[count]->setPos((count*150)+150, (count*150)+150);
}
ui->TileView->setScene(scene);