Ich habe ein Program mit QGraphicsScene geschrieben. QGraphicsScene besteht aus GraphicsTextItem und man kann mit diesem Item wie ein Texteditor arbeiten. Das heisst die markierten Text editierber, Fontänderbar usw..
Mein Problem ist, obwohl ich Font des Texts wechseln kann, kann ich die Farbe nicht wechseln.
Hat jemand Idee?
Mein Quellcode:
Code: Alles auswählen
void Scene::set_Font_Color(const QFont &font, const QColor &color)
{
if (isItemChange(DiagramTextItem::Type))
{
QGraphicsTextItem *item =qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first());
if (item)
{
QTextCursor textCursor = item->textCursor();
if( textCursor.hasSelection() )
{
QTextCharFormat format;
format.setFont(font);
item->textCursor().setCharFormat(format);// change Font
// how can i change the color now?
}
}
}
}