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:
{
Q_OBJECT
public:
/*!
Class initializer,
- str: supply a string to display
*/
class FieldBoundText : public QGraphicsTextItem
{
Q_OBJECT
public:
/*!
Class initializer,
- str: supply a string to display
*/
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:
protected:
/*!
Reimplementing painter class for Antialiasing the font
*/
protected:
/*!
Reimplementing painter class for Antialiasing the font
*/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
To copy to clipboard, switch view to plain text mode
Which looks like:
painter
->setRenderHints
(QPainter::Antialiasing|QPainter
::TextAntialiasing);
}
void FieldBoundText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
QGraphicsTextItem::paint(painter,option,widget);
}
To copy to clipboard, switch view to plain text mode
Implementing the code like:
FieldBoundText
*txt
= new FieldBoundText
(QString("%1").
arg(corner
));
txt->setPos(xStart,0);
txt->setRotation(-45.0);
FieldBoundText *txt = new FieldBoundText(QString("%1").arg(corner));
txt->setPos(xStart,0);
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
Bookmarks