Seite 1 von 1

Selected Text Color

Verfasst: 3. April 2009 13:25
von Tuvshin
Hallo!
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?
             }
        }
    }
}

Verfasst: 3. April 2009 13:52
von pfid

Code: Alles auswählen

void QTextFormat::setForeground ( const QBrush & brush )
in deinem Beispiel:

Code: Alles auswählen

format.setForeground(QColor(Qt::red))
Btw es wäre toll wenn du Quellcode in

Code: Alles auswählen

[/code ] Tags packen würdest.

danke

Verfasst: 3. April 2009 14:02
von Tuvshin
Es funktioniert!! Danke pfid. :D