Hi there!
I'm afraid it is not. The solid black background stays in my application. As you suggested, I continued our minimal error example in introducing the 3DTextItem and a dummy ProjectedItem. Sadly, still works.
main.cpp:
#include <QtGui>
#include <QGLWidget>
#include "textitem.h"
{
protected:
{
glClearColor(1.0,1.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
};
int main(int argc, char **argv){
CGLScene scene;
view.setScene(&scene);
CGL3dTextItem* item = new CGL3dTextItem("");
item->setHTML("<font color=#FF0000>FAT TEST </font>");
scene.addItem(item);
f.setPointSize(36);
item->setFont(f);
//item->setCacheMode(QGraphicsItem::ItemCoordinateCache);
QTransform trans;
trans.rotate(60, Qt::YAxis);
item->setTransform(trans);
item->setOpacity(1);
view.show();
return app.exec();
}
#include <QtGui>
#include <QGLWidget>
#include "textitem.h"
class CGLScene : public QGraphicsScene
{
protected:
void drawBackground(QPainter *painter, const QRectF &rect)
{
glClearColor(1.0,1.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
QGraphicsView view;
CGLScene scene;
view.setScene(&scene);
view.setViewport(new QGLWidget);
CGL3dTextItem* item = new CGL3dTextItem("");
item->setHTML("<font color=#FF0000>FAT TEST </font>");
scene.addItem(item);
QFont f;
f.setPointSize(36);
item->setFont(f);
item->setFlag(QGraphicsItem::ItemIsMovable);
//item->setCacheMode(QGraphicsItem::ItemCoordinateCache);
QTransform trans;
trans.rotate(60, Qt::YAxis);
item->setTransform(trans);
item->setOpacity(1);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
textitem.h - a separate header file for moc to start up.
#ifndef TEXTITEM_H
#define TEXTITEM_H
#include <QtGui>
#include <QObject>
{ Q_OBJECT
protected:
virtual QRectF boundingRect
() const {return shape
().
boundingRect();
} virtual QPainterPath shape
() const {QPainterPath p;QPolygonF polygon
= mapToScene
(this
->childrenBoundingRect
());p.
addPolygon(polygon
);return p;
} };
class CGL3dTextItem : public CGL3dProjectedItem
{ Q_OBJECT
Q_PROPERTY(QObject* textitem READ getTextItem
) Q_PROPERTY(QString text READ getText WRITE setText
) Q_PROPERTY(QString html READ getHTML WRITE setHTML
) Q_PROPERTY(QFont font READ getFont WRITE setFont
) public:
CGL3dTextItem
(QString text
) : CGL3dProjectedItem
() {
_textitem->setTextInteractionFlags(Qt::TextBrowserInteraction);
textoption.
setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
_textitem->document()->setDefaultTextOption(textoption);
//setHandlesChildEvents(true);
}
enum { Type = UserType+2};
int type() const { return Type;}
QObject* getTextItem
() {return _textitem;
} QString getText
() {return _textitem
->toPlainText
();
} void setText
(QString plaintext
) {_textitem
->setPlainText
(plaintext
);TextChanged
();
} QString getHTML
() {return _textitem
->toHtml
();
} void setHTML
(QString htmltext
) {_textitem
->setHtml
(htmltext
);TextChanged
();
} QFont getFont
() {return _textitem
->font
();
} void setFont
(QFont f
) {_textitem
->setFont
(f
);TextChanged
();
} protected:
void TextChanged()
{
// SetCenterPos(CGL3d(-_textitem->document()->size().width()/2,0,0));
//qDebug() << "TextItem Center: " << CenterPos().toString();
}
private:
};
#endif // TEXTITEM_H
#ifndef TEXTITEM_H
#define TEXTITEM_H
#include <QtGui>
#include <QObject>
class CGL3dProjectedItem : public QObject, public QGraphicsItem
{ Q_OBJECT
protected:
virtual QRectF boundingRect() const {return shape().boundingRect();}
virtual QPainterPath shape() const {QPainterPath p;QPolygonF polygon = mapToScene(this->childrenBoundingRect());p.addPolygon(polygon);return p;}
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) {}
};
class CGL3dTextItem : public CGL3dProjectedItem
{ Q_OBJECT
Q_PROPERTY(QObject* textitem READ getTextItem)
Q_PROPERTY(QString text READ getText WRITE setText)
Q_PROPERTY(QString html READ getHTML WRITE setHTML)
Q_PROPERTY(QFont font READ getFont WRITE setFont)
public:
CGL3dTextItem(QString text) : CGL3dProjectedItem()
{
_textitem = new QGraphicsTextItem(text,this);
_textitem->setTextInteractionFlags(Qt::TextBrowserInteraction);
QTextOption textoption(Qt::AlignCenter);
textoption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
_textitem->document()->setDefaultTextOption(textoption);
_textitem->setCacheMode(QGraphicsItem::ItemCoordinateCache);
//setHandlesChildEvents(true);
}
enum { Type = UserType+2};
int type() const { return Type;}
QObject* getTextItem() {return _textitem;}
QString getText() {return _textitem->toPlainText();}
void setText(QString plaintext) {_textitem->setPlainText(plaintext);TextChanged();}
QString getHTML() {return _textitem->toHtml();}
void setHTML(QString htmltext) {_textitem->setHtml(htmltext);TextChanged();}
QFont getFont() {return _textitem->font();}
void setFont(QFont f) {_textitem->setFont(f);TextChanged();}
protected:
void TextChanged()
{
// SetCenterPos(CGL3d(-_textitem->document()->size().width()/2,0,0));
//qDebug() << "TextItem Center: " << CenterPos().toString();
}
private:
QGraphicsTextItem* _textitem;
};
#endif // TEXTITEM_H
To copy to clipboard, switch view to plain text mode
So maybe the problem is hidden in the kind of transformation I am doing. I will investigate.
Thx
Joh
Bookmarks