Results 1 to 5 of 5

Thread: QGraphicsText Item Rotation and antialiasing

  1. #1
    Join Date
    Dec 2012
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QGraphicsText Item Rotation and antialiasing

    Dear All,
    I have Antialiasing problem with the rotated text in QGraphicsView. I have found some bugs regarding the same problem and I have tried the latest Qt Version (5.0.0 RC2), but the problem is still not Fixed. Does someone know a workaround?
    I have the following code:
    Qt Code:
    1. class FieldBoundText : public QGraphicsTextItem
    2. {
    3. Q_OBJECT
    4. public:
    5. /*!
    6.   Class initializer,
    7.   - str: supply a string to display
    8.   */
    9. FieldBoundText(QString str, QGraphicsItem * parent = 0);
    To copy to clipboard, switch view to plain text mode 
    and have re-implemented the paint function for the class to add Anti-Aliasing:
    Qt Code:
    1. protected:
    2. /*!
    3.   Reimplementing painter class for Antialiasing the font
    4.   */
    5. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    To copy to clipboard, switch view to plain text mode 
    Which looks like:
    Qt Code:
    1. void FieldBoundText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    2. painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
    3. QGraphicsTextItem::paint(painter,option,widget);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Implementing the code like:
    Qt Code:
    1. FieldBoundText *txt = new FieldBoundText(QString("%1").arg(corner));
    2. txt->setPos(xStart,0);
    3. txt->setRotation(-45.0);
    To copy to clipboard, switch view to plain text mode 
    Results in the text without Anti-aliasing :
    No-Anti-Aliasing.JPG

    Please let me know if there is some work around for this problem?

    - Yogesh Upreti

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsText Item Rotation and antialiasing

    In your QGraphicsView
    Qt Code:
    1. setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) );
    2.  
    3. QGLFormat frm = wgt->format();
    4. frm.setSamples(4);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsText Item Rotation and antialiasing

    QGLFormat frm = wgt->format();
    frm.setSamples(4);
    "frm" is a copy of the widget's QGLFormat. Don't you need to call QGLWidget::setFormat() method before these changes will have any effect on the widget?

  4. #4
    Join Date
    Dec 2012
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsText Item Rotation and antialiasing

    Hello Jonny,
    I have already Antialiasing on in my QGraphicsView

    I have following on :
    QPainter::Antialiasing, QPainter::TextAntialiasing, QPainter::HighQualityAntialiasing

    But still no effect.

    Although I am not sure what QGLFormat have to do with this??

    Quote Originally Posted by Jonny174 View Post
    In your QGraphicsView
    Qt Code:
    1. setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) );
    2.  
    3. QGLFormat frm = wgt->format();
    4. frm.setSamples(4);
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QGraphicsText Item Rotation and antialiasing

    Please provide a minimal compilable example reproducing the problem.
    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. QSvgRenderer antialiasing
    By jonks in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2013, 09:39
  2. Best AntiAliasing?
    By beni46 in forum Qwt
    Replies: 2
    Last Post: 2nd February 2010, 13:28
  3. QGraphicsView: per-item antialiasing specification?
    By mattc in forum Qt Programming
    Replies: 5
    Last Post: 3rd May 2009, 13:30
  4. QImage antialiasing
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 19:37
  5. Font not Antialiasing
    By ChasW in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2007, 18:12

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.