Results 1 to 4 of 4

Thread: Strange QPainter: low resolution

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Strange QPainter: low resolution

    How is it possible that I get a similar bad drawing?
    The code is quite standard:
    Qt Code:
    1. SurfaceWidget::SurfaceWidget(QWidget* parent): QWidget(parent)
    2. {
    3. azimuth = 0;
    4. setBackgroundRole(QPalette::Base);
    5. setAutoFillBackground(true);
    6. }
    7.  
    8.  
    9.  
    10. void SurfaceWidget::paintEvent(QPaintEvent* /*event*/)
    11. {
    12. QPainter painter(this);
    13. painter.setRenderHint(QPainter::Antialiasing,true);
    14. int side = qMin(width(),height());
    15. painter.setViewport(0, 0,side,side);
    16.  
    17. qDebug()<<"Surface"<<width()<<height();
    18. painter.setWindow(-50,-50,50,50);
    19. draw(&painter);
    20. }
    21. void SurfaceWidget::draw(QPainter * painter)
    22. {
    23. painter->translate(+0.5, +0.5);
    24. painter->setPen(QPen(Qt::black,1 ,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
    25. painter->setBrush(QBrush(Qt::blue,Qt::BDiagPattern));
    26. painter->drawRect(-50,-50,40,20);
    27. painter->drawRect(QRect(0, 0, width() - 1, height() - 1));
    28. }
    29. QSize SurfaceWidget::minimumSizeHint() const
    30. {
    31. return QSize(100, 100);
    32. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange QPainter: low resolution

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange QPainter: low resolution

    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....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange QPainter: low resolution

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QT Resolution solution : Need suggestion
    By soumyadeep_pan in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2009, 10:05
  2. Strange behaviour of QPainter...
    By oscar in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2008, 12:07
  3. QPainter strange warning
    By mchara in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 02:06
  4. Replies: 7
    Last Post: 20th March 2006, 20:03
  5. 2 Questions about QPainter
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 22nd February 2006, 15:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.