PDA

View Full Version : Qt 4.1.0 QPainter



standrvr17
6th February 2006, 16:30
Hi all, I just started porting my code from 3.3 to 4.1. I noticed that QPainter doesn't print as nicely as it did in 3.3. Most notably, painting on small widgets results in constricted or missing line segments. As you resize the widget, the missing lines begin to fill in.. I was just wondering if there was something to turn this off. I tried antialiasing and it made it slightly better....

P.s I think it's great what you guys are doing, moving to this new site and all, keep up the good work to keep this community growing...

thanks guys

wysota
6th February 2006, 18:45
You could start by showing your code :)

standrvr17
6th February 2006, 20:13
hi, the problem isn't my code. I am only drawing simple shapes on a QPainter widget with a viewport and window defined so the whole thing can expand. QT4 QPainter paints differently than QT3. I think it could be because they changed the pixel width of the pen to accomidate QPolygons..

reimplement paintEvent and put this in it, compile with qt3 and run it, then compile with qt4 and run, expand the widget and pay close attention to the lines of the rectangle, they change thicknesses with each repaint...(with qt4)

but maybe I am doing something wrong, if you try this, let me know if you don't notice any change.



QPainter myPainter;
myPainter.begin(this);
int shortSide = qMin(width(), height());
myPainter.setViewport(((width()-shortSide)/3, (height()-shortSide)/3, shortside, shortSide);
myPainter.serWindow(-50,-50,100,100);
myPainter.setPen(Qt::black);
myPainter.drawRect(-25,-25,45,60);
myPainter.end();

wysota
6th February 2006, 23:30
hi, the problem isn't my code. I am only drawing simple shapes on a QPainter widget with a viewport and window defined so the whole thing can expand. QT4 QPainter paints differently than QT3. I think it could be because they changed the pixel width of the pen to accomidate QPolygons..

I'm sure it is about your code, as other things in Qt are drawn correctly and QPainter is used for that ;)



reimplement paintEvent and put this in it, compile with qt3 and run it, then compile with qt4 and run, expand the widget and pay close attention to the lines of the rectangle, they change thicknesses with each repaint...(with qt4)

but maybe I am doing something wrong, if you try this, let me know if you don't notice any change.

No, you're not doing anything wrong.


myPainter.setViewport(((width()-shortSide)/3, (height()-shortSide)/3, shortside, shortSide);
myPainter.serWindow(-50,-50,100,100);
myPainter.setPen(Qt::black);

Ok, this seems to be the problem. In Qt4 the pen size is scaled when scaling the "canvas". I guess setting the window and viewport sizes cause the canvas to be scaled (which is quite logic) and pen gets scaled with it. It's an unwanted behaviour in this situation... You may look if there is a switch, which turns this off. If not, I think you should fill in a bug report :) Just remember, the scaling is intended! You just want some other behaviour that the standard one, so it'll rather be a "feature request" than a bug report.