PDA

View Full Version : Strange QPainter: low resolution



giusepped
16th April 2009, 10:40
How is it possible that I get a similar bad drawing?
The code is quite standard:


SurfaceWidget::SurfaceWidget(QWidget* parent): QWidget(parent)
{
azimuth = 0;
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
}



void SurfaceWidget::paintEvent(QPaintEvent* /*event*/)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true) ;
int side = qMin(width(),height());
painter.setViewport(0, 0,side,side);

qDebug()<<"Surface"<<width()<<height();
painter.setWindow(-50,-50,50,50);
draw(&painter);
}
void SurfaceWidget::draw(QPainter * painter)
{
painter->translate(+0.5, +0.5);
painter->setPen(QPen(Qt::black,1 ,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
painter->setBrush(QBrush(Qt::blue,Qt::BDiagPattern));
painter->drawRect(-50,-50,40,20);
painter->drawRect(QRect(0, 0, width() - 1, height() - 1));
}
QSize SurfaceWidget::minimumSizeHint() const
{
return QSize(100, 100);
}

wysota
16th April 2009, 11:38
You told your painter that the canvas is 50x50 in size so it draws the box in such resolution. The raster seems to be not antialiased (antialiasing a raster would blur it, so I guess this is intentional) and hence you get what you get. Even if it was antialiased the result would look bad - the painter can't paint fractions of a pixel here. You might try with "F" versions of painting methods (i.e. drawRectF) but I'm not sure it will make a difference in this case. It'll be better if you don't set the window size.

giusepped
17th April 2009, 03:19
You're right, now it is ok.
But in this case, it means that I am missing something.
The Window is just a logical coordinates system, isn't it? While the Viewport is the physical coordinates system, right?
So, why the resolution correspond to the Window ?
Maybe I am confused....:confused:

wysota
17th April 2009, 08:49
Because it is the "logical" resolution that's messing things up. It's based on integer, not real values and the raster is drawn in logical coordinates. Thus the rectangle is antialiased correctly (in physical coordinates) but the raster is not antialiased at all so you see aliasing.