QPainter Problem
Verfasst: 2. Juli 2008 09:22
Hallo,
ich habe folgendes was funktioniert
Ich lege QPainter in jedem paint Event neu an, ich moechte QPainter nun als Klassenvariable anlegen damit ich QPainter nicht immer wieder neu erzeugen muss. Das obige auslesen kostet zuviel Zeit und ist nur einmal am Anfang und bei Aenderung der Fenstergroesse notwendig.
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:
Beim ausfuehren bekomme ich
Was will mir das sagen? Wo ist der Denkfehler?
Danke!
J.
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.