ich habe folgendes was funktioniert
Code: Alles auswählen
void RenderArea::paintEvent(QPaintEvent * /* event */){
int blockSize = width() / 31;
QRectF bounds(0,0,blockSize,blockSize);
QPainter painter(this);
QFile myFile("/path/1.txt");
if (!myFile.open(QIODevice::ReadOnly | QIODevice::Text)) return;
QTextStream in(&myFile);
while (!in.atEnd()){
QString line = in.readLine();
for(int i=0; i < 31; i++){
int squareType = line.section(',',i,i).toInt();
if (squareType == 0){
painter.translate(blockSize,0);
continue;
}
QString squarePath = "/path/"+fieldItemMap.value(squareType)+".svg";
renderer = new QSvgRenderer(squarePath);
renderer -> render(&painter,bounds);
painter.translate(blockSize,0);
}
painter.translate(-blockSize*31,blockSize);
}
}
Ich habe also ganz naiv im .h file QPainter* background; deklariert, und im Konstruktor meiner Klasse RenderArea background = new QPainter(this);
Das Paint Event habe ich entsprechend so geaendert:
Code: Alles auswählen
void RenderArea::paintEvent(QPaintEvent * /* event */){
int blockSize = width() / 31;
// QPainter nicht mehr angelegt da Klassenvariable
QFile myFile("/path/1.txt");
if (!myFile.open(QIODevice::ReadOnly | QIODevice::Text)) return;
QTextStream in(&myFile);
while (!in.atEnd()){
QString line = in.readLine();
for(int i=0; i < 31; i++){
int squareType = line.section(',',i,i).toInt();
if (squareType == 0){
background -> translate(blockSize,0); // aus . ein -> gemacht da jetzt pointer
continue;
}
QString squarePath = "/path/"+fieldItemMap.value(squareType)+".svg";
renderer = new QSvgRenderer(squarePath);
renderer -> render(background,bounds);
background ->translate(blockSize,0); // aus . ein -> gemacht da jetzt pointer
}
background -> translate(-blockSize*31,blockSize); // aus . ein -> gemacht da jetzt pointer
}
}
Code: Alles auswählen
QPainter::restore: Unbalanced save/restore
QPainter::setMatrix: Painter not active
QPainter::save: Painter not active
QPainter::setMatrix: Painter not active
QPainter::setMatrix: Painter not active
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setMatrix: Painter not active
QPainter::setMatrix: Painter not active
QPainter::restore: Unbalanced save/restore
QPainter::setMatrix: Painter not active
QPainter::save: Painter not active
QPainter::setMatrix: Painter not active
QPainter::setMatrix: Painter not active
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::restore: Unbalanced save/restore
QPainter::setMatrix: Painter not active
QPainter::setMatrix: Painter not active
Danke!
J.