Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QGraphicsTextItem multiple fonts
I am makings a graphics editor. It seems QT does almost exactly what I want. But it seems QGraphicsTextItem can only handle one font. Is there a way to get QGraphicsTextItem to handle multiple fonts? Or alternatively, is there an easy way to get QTextEdit to interact with a QGraphicsScene?
Thanks in advanced
Thanks or your quick reply. I understand that I can set the font for the entire string inside the QGraphicsTextItem. I want to have MULTIPLE fonts within a SINGLE QGraphicsTextItem though. Is there any simple way to do this? using setFont() will change the font for the entire item, not any new text entered, for example.
I think the easiest way is "QGraphicsTextItem::setHtml":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#setHtml
<font face="times, times new roman, serif" size=4>This is times or times new roman</font>
will write "This is times or times new roman" with point size = 4
Is there an easy way to this though? When a user clicks the BOLD button, i want to be able to insert the selected or new text as bold. This seems to be a nontrivial task if I am going to be dealing with many user inputs and html. QTextEdit seems to support what I need, is there a way to make this place nicely with graphicsCanvas?
Other solution is to "QGraphicsTextItem::setDocument":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#setDocument
Also can override "QGraphicsTextItem::paint":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicstextitem.html#paint and draw text as you want.
Also you can use "QGraphicsProxyWidget":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsproxywidget.html and "setWidget":http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsproxywidget.html#setWidget your QTextEdit
thanks, I'll look into these three possibilities
bq. The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit.
QTextDocument is a container for structured rich text documents, providing support for styled text and various types of document elements, such as lists, tables, frames, and images. They can be created for use in a QTextEdit, or used independently.
Jupiter last edited by
you can also use qtextcharformat and merge it