QtのQGraphicsSceneに10ミリ秒のグリッドを描画しようとしています。私はQtにあまり詳しくありません...それは私が初めて使用したものであり、アプリケーションがWindowsとLinuxの間で移植可能である必要があるという理由だけです。
実際、グリッドの描画に問題はありません。グリッドが大きくなったときのパフォーマンスだけです。表示するプログラムに新しいデータがロードされた場合、グリッドはSceneRectに合わせてサイズを変更できる必要があります。
これは私が今それをする方法です、私はこれを嫌います、しかしそれは私がそれをすることを考えることができる唯一の方法です...
void Plotter::drawGrid() {
unsigned int i;
QGraphicsLineItem *line;
QGraphicsTextItem *text;
char num[11];
QString label;
unsigned int width = scene->sceneRect().width();
unsigned int height = scene->sceneRect().height();
removeGrid();
for (i = 150; i < width; i+= 10) {
line = new QGraphicsLineItem(i, 0, i, scene->sceneRect().height(), 0, scene);
line->setPen(QPen(QColor(0xdd,0xdd,0xdd)));
line->setZValue(0);
_itoa_s(i - 150, num, 10);
label = num;
label += " ms";
text = new QGraphicsTextItem(label, 0, scene);
text->setDefaultTextColor(Qt::white);
text->setX(i);
text->setY(height - 10);
text->setZValue(2);
text->setScale(0.2);
//pointers to items stored in list for removal later.
gridList.append(line);
gridList.append(text);
}
for (i = 0; i < height; i+= 10) {
line = new QGraphicsLineItem(150, i, width, i, 0, scene);
line->setPen(QPen(QColor(0xdd,0xdd,0xdd)));
line->setZValue(0);
gridList.append(line);
}
}
ただし、scene->sceneRect()。width()が大きくなりすぎると、アプリケーションの動作が非常に遅くなります。QGLWidgetを使用してみましたが、速度の向上はせいぜいわずかです。