Seite 1 von 1

prevent "monster paintEvent - method"

Verfasst: 9. Juni 2009 22:35
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

Verfasst: 9. Juni 2009 22:55
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..

Verfasst: 9. Juni 2009 23:21
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"

Re: prevent "monster paintEvent - method"

Verfasst: 10. Juni 2009 08:14
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.

Re: prevent "monster paintEvent - method"

Verfasst: 10. Juni 2009 16:10
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