项目场景:
提示:这里简述项目相关背景:
Windows上用QGraphicsView显示大量图片,并进行走马灯式的展示
问题描述:
用MSVC2019编译会显示不出图片
解决方案:
换MinGW编译
====================================================
问题描述:
自己new的glWidget当图很大时只会显示黑色
// OpenGL
// 自己new的glWidget当图很大时只会显示黑色
// ui->gvl->setViewport(new QGLWidget(QGLFormat(QGL::Rgba)));
// ui->gvm->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
// ui->gvr->setViewport(new QGLWidget(QGLFormat(QGL::SingleBuffer)));
解决方案:
用QOpenGLWidget,别用QGLWidget
// 但用控件的glWidget可以绘很大的图
// 用OpenGL很占内存,40节车厢用掉将近3G内存,不用OpenGL反而只用了100多M
// ui->gvl->setViewport(ui->gll);
// ui->gvm->setViewport(ui->glm);
// ui->gvr->setViewport(ui->glr);
====================================================
问题描述:
子线程中创建QGraphicsScene会导致啥也不显示
// // 啥也不显示,看来只能在UI线程中初始化
// this->m_spScene_l.reset(new QGraphicsScene(this));
// this->m_spScene_m.reset(new QGraphicsScene(this));
// this->m_spScene_r.reset(new QGraphicsScene(this));
解决方案:
只能在UI线程中创建QGraphicsScene
====================================================
问题描述:
子线程中直接添加QGraphicsItem会导致RtlReAllocateHeap失败的异常,猜想是线程冲突导致
解决方案:
// 先禁止控件自动更新,在添加新单元,否则可能会导致RtlReAllocateHeap失败的异常,
// 猜想是线程冲突导致,所以先禁止ui线程操作
ui->gvl->setUpdatesEnabled(false);
ui->gvm->setUpdatesEnabled(false);
ui->gvr->setUpdatesEnabled(false);
this->m_spScene_l->addItem(iteml);
cout << "l" << endl;
this->m_spScene_m->addItem(itemm);
cout << "m" << endl;
this->m_spScene_r->addItem(itemr);
cout << "r" << endl;
ui->gvl->setUpdatesEnabled(true);
ui->gvm->setUpdatesEnabled(true);
ui->gvr->setUpdatesEnabled(true);
====================================================
问题描述:
怎么刷新都不显示,一片空白
解决方案:
用QGraphicsView的setTransform方法设置不等于1倍的缩放,可以将添加的item们显示出来。
QTransform matrix;
matrix.scale(rScale / 1, rScale / 1);
ui->gvl->setTransform(matrix);
ui->gvm->setTransform(matrix);
ui->gvr->setTransform(matrix);
====================================================
问题描述:
只显示一部分item内容,其他的显示不出来
解决方案:
// 就这个好使,能强制刷新
this->m_spScene_l->update(iteml1->pos().x(),
iteml1->pos().y(),
iteml1->boundingRect().width(),
iteml1->boundingRect().height());
this->m_spScene_m->update(itemm1->pos().x(),
itemm1->pos().y(),
itemm1->boundingRect().width(),
itemm1->boundingRect().height());
this->m_spScene_r->update(itemr1->pos().x(),
itemr1->pos().y(),
itemr1->boundingRect().width(),
itemr1->boundingRect().height());