PDA

View Full Version : Rich text in QGraphicsTextItem



maverick_pol
29th September 2008, 11:32
Hi guys,

I have my items(derived from QGraphicsTextItem. These items are children of other items. I enter some text in QtextEdit and use the text document from the textEdit to set text to my text items. Still, when setting the textDocument for the textItem I only get plain text. I also tried settings HTML for my items, but still I only see plain text.
Any idea, why I can't display a rich text in QGraphicsTextItem?


Thanks,

Kacper

jpn
29th September 2008, 18:46
What does the subclass do? It works with plain QGraphicsTextItem.

patrik08
29th September 2008, 19:07
try to clone document
QTextDocument * QTextDocument::clone ( QObject * parent = 0 ) const
and after insert on QGraphicsTextItem

void QGraphicsTextItem::setDocument ( QTextDocument * document )

at end only document()->setPageSize ( docoriginal->pageSize() )
to fit on size...

if not run display your code section.

or try to build
http://code.google.com/p/fop-miniscribus/ screenshot bottom
it edit QTextDocument inside QGraphicsRectItem each page.
the base is http://fop-miniscribus.googlecode.com/svn/trunk/QTextPanel/

maverick_pol
29th September 2008, 21:08
Hi,

Thanks for the explanation; I tried most of the ideas, but did not set 'pagesize'. I will set pagesize and see if it helps.

{edited} ok, I solved the problem;
[SOLVED]

THanks,

Kacper


[EDITED]
The ideas are good, but are not working in my code.
Piece of my code


...//_doc is QTextEdit->document();
// When I qDebug()<<_doc it shows multiple lines
// when setting on item the text is only one line.
// I simply need multiple lines of text ( Max 5 lines 20 char each, etc)
void MyItem::vUpdateText(QTextDocument* _doc)
{
m_textDoc = _doc->clone();
setDocument(m_textDoc);
document()->setPageSize(_doc->pageSize());
update(boundingRect());
}