PDA

View Full Version : QGraphicsText Item Rotation and antialiasing



yogeshupreti
19th December 2012, 16:00
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:


class FieldBoundText : public QGraphicsTextItem
{
Q_OBJECT
public:
/*!
Class initializer,
- str: supply a string to display
*/
FieldBoundText(QString str, QGraphicsItem * parent = 0);


and have re-implemented the paint function for the class to add Anti-Aliasing:


protected:
/*!
Reimplementing painter class for Antialiasing the font
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

Which looks like:


void FieldBoundText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
painter->setRenderHints(QPainter::Antialiasing|QPainter::Te xtAntialiasing);
QGraphicsTextItem::paint(painter,option,widget);
}

Implementing the code like:


FieldBoundText *txt = new FieldBoundText(QString("%1").arg(corner));
txt->setPos(xStart,0);
txt->setRotation(-45.0);

Results in the text without Anti-aliasing :
8514

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

- Yogesh Upreti

Jonny174
20th December 2012, 05:14
In your QGraphicsView


setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );




new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) );

QGLFormat frm = wgt->format();
frm.setSamples(4);

d_stranz
20th December 2012, 16:40
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?

yogeshupreti
22nd December 2012, 23:53
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??


In your QGraphicsView


setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );




new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) );

QGLFormat frm = wgt->format();
frm.setSamples(4);

wysota
23rd December 2012, 02:20
Please provide a minimal compilable example reproducing the problem.