prevent "monster paintEvent - method"

Alles zum Qt Framework für Java
Antworten
MrG
Beiträge: 4
Registriert: 9. Juni 2009 21:25

prevent "monster paintEvent - method"

Beitrag von MrG »

Hello,

to paint, qtjambi uses the paintEvent method.

i would like to write a little cartesian coordinate plane to display some charts.
there should be the option to
set the x- and y-axes visible/invisble
set the marks of the axes visible/invisble
set a legend visible/invisble
set a gray grid of helplines visible/invisble
change the background color
change the scaling

now i am afraid that the paintEvent will be a monster with tons of "if else"

if(showXAxis){
myQPainter.doThis()
}
if(showHelplines){
myQPainter.doThat()
}

is there a way to keep paintEvent small and clearly??

and i ask myself how different classes can paint on the canvas?

is it possible to calculate the hundrets of points of a chart in a different class, that just passes a "painting object" to the canvas?

like a small painting application with one canvas and some buttons.
one button "paint Rectangle"
one button "paint Circle"
one button "paint Star"
...

a class CalculateTheCircle should calculate and pass just a circle to the canvas ..

thanks for any hint

beste gruesse
jochen
franzf
Beiträge: 3114
Registriert: 31. Mai 2006 11:15

Beitrag von franzf »

Geb dir doch ETWAS Mühe mit deinem ersten Post.
Das schaut so aus als hättest du das gerade eben auch in nem englischen Forum gepostet und hier auch mit reingehauen, ohne es in die Sprache des Forums hier zu übersetzen (Deutsch, dem du ja scheinbar mächtig bist).
Und dann auch noch ohne CODE-Tags... Würde mich wundern wenn da so bald jemand nützliche Tips postet..
MrG
Beiträge: 4
Registriert: 9. Juni 2009 21:25

Beitrag von MrG »

Du hast recht,
Das ist ein schlechter Start.

Entschuldigung

Ich habe den Text heute unterwegs in der Annahme geschrieben, heute abend ein englisches Forum zu finden.

In der Hoffnung auf viele Tipps, nochmals "sorry"
franzf
Beiträge: 3114
Registriert: 31. Mai 2006 11:15

Re: prevent "monster paintEvent - method"

Beitrag von franzf »

Mit den paar Optionen hast du doch keine "tons of if/else".
Aber schau dir doch auch mal die Examples an, da siehst du oft, dass bei komplexeren Sachen das Zeichen in ne (private) Methode der Klasse ausgelagert wird.

Code: Alles auswählen

MyWidget::drawFancyStuff( QPainter& p );
Und darin wird dann dieser Painter genutzt zum zeichnen.
Du könntest jetzt z.B. ne Methode definieren zum malen des Grid, der Marker, usw. Aber das Abfargen bleibt dir nicht erspart.
Ist aber eher eine grundsätzliche C++-Angelegenheit (Auslagern von speziellen Sachen in Methoden) als ein QWidget/QPainter-Problem.
MrG hat geschrieben:and i ask myself how different classes can paint on the canvas?

is it possible to calculate the hundrets of points of a chart in a different class, that just passes a "painting object" to the canvas?
Übersetz das mal bitte in ordentliches Deutsch. was ist ein "painting object"?

Aber vllt. meinst du ja sowas wie das "Graphics View Framework" in Qt4.
MrG
Beiträge: 4
Registriert: 9. Juni 2009 21:25

Re: prevent "monster paintEvent - method"

Beitrag von MrG »

franzf hat geschrieben: Aber schau dir doch auch mal die Examples an, da siehst du oft, dass bei komplexeren Sachen das Zeichen in ne (private) Methode der Klasse ausgelagert wird.

Code: Alles auswählen

MyWidget::drawFancyStuff( QPainter& p );
Und darin wird dann dieser Painter genutzt zum zeichnen.

Code: Alles auswählen

private void paintRect(QPainter p){
    	p.setBrush(QColor.darkYellow);
    	p.drawRect(30, 30, 80, 80);
}
    
protected void paintEvent(QPaintEvent e) {
    	QPainter p = new QPainter(this);
    	paintRect(p);
}
:-)
franzf hat geschrieben: Übersetz das mal bitte in ordentliches Deutsch. was ist ein "painting object"?
Hat sich erledigt.

Vielen Dank
Antworten