Results 1 to 5 of 5

Thread: Strange behaviour with QPen

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Strange behaviour with QPen

    Hi to all,
    I have to draw some lines in the paint event of an widget.
    I set a pen with width = 1 but the real width of the pen is visibility bigger than 1 pixel and the width method
    return 1 as value...odd

    Here some code:

    Qt Code:
    1. QPixmap temp = QPixmap( w, h ); // I draw on a pixel to cache
    2.  
    3. QPainter p( &temp );
    4. p.setRenderHint( QPainter::Antialiasing, true );
    5. p.fillRect( temp.rect(), Qt::lightGray );
    6.  
    7. // temporal line
    8. QPen pen(Qt::black, 1); //<---- 1 pixel wide
    9. pen.setStyle(Qt::SolidLine);
    10. p.setPen(pen);
    11. p.drawLine(0, 20, w, 20); //width of the line bigger than 1 pixel
    12. qDebug() << "Pen width: " << pen.width(); // returns 1
    To copy to clipboard, switch view to plain text mode 

    Any idea?

    Best
    Franco Amato

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange behaviour with QPen

    What does it look like when you don't use QPainter::Antialiasing?

    And what happens when you set pen width to zero: a "cosmetic pen"? That one should always draw 1 pixel wide.

  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange behaviour with QPen

    Quote Originally Posted by boudie View Post
    What does it look like when you don't use QPainter::Antialiasing?

    And what happens when you set pen width to zero: a "cosmetic pen"? That one should always draw 1 pixel wide.
    I removed the Antialiasing flag and seems solved the problem but why???
    Franco Amato

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange behaviour with QPen

    your painted line will have some strange looking like a small saw tooth wave normally rather than straight .. try to draw a cross line u can see it clearly .. antialiasing is like coating or filling the scramble space ..
    see the link
    http://doc.trolltech.com/4.3/coordsy...iased-painting
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange behaviour with QPen

    Quote Originally Posted by wagmare View Post
    your painted line will have some strange looking like a small saw tooth wave normally rather than straight .. try to draw a cross line u can see it clearly .. antialiasing is like coating or filling the scramble space ..
    see the link
    http://doc.trolltech.com/4.3/coordsy...iased-painting
    Thank you for your explanation. This is why the width of my line is bigger than 1 pixel
    Franco Amato

Similar Threads

  1. Strange behaviour with QPainter
    By franco.amato in forum Qt Programming
    Replies: 12
    Last Post: 14th January 2010, 05:30
  2. Need help: Strange behaviour
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 04:03
  3. Strange behaviour of QPainter...
    By oscar in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2008, 12:07
  4. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.