Seite 1 von 1

QAbstractTextDocumentLayout cursor palette

Verfasst: 30. April 2008 10:06
von patrik08
Ich bin gerade drann ein QTextDocument im QGraphicsItem zu zeichnen
doch nicht QGraphicsTextItem .

Nun mochte ich die farbe palette vom blink cursor aendern ...
( geht doch nicht schwarzer cursor auf schwarzer hindergrund!)

Ich moechte die gegenfarbe setzen vom hindergrund etwa so

Code: Alles auswählen


 const QColor fgcolor = backgroundfarbe;
    const QColor ebgcolor(
        fgcolor.red()   > 127 ? 0 : 255,
        fgcolor.green() > 127 ? 0 : 255,
        fgcolor.blue()  > 127 ? 0 : 255);
die doc sagt auch nicht viel.... wo ich diese cursor color palette finde.

http://doc.trolltech.com/4.3/qabstractt ... ntext.html

den QTextDocument zeichne ich so...

Code: Alles auswählen


void TextWriter::paint_doc(  QPainter * painter ,
                         const QStyleOptionGraphicsItem *option , 
                         QBrush BGpage , 
                         const QRectF fulllayer ,  
                         bool alternate )
{
	  /* Layer Background draw! */
		painter->save();
		painter->setPen(Qt::NoPen);
		painter->setBrush(BGpage);
		painter->drawRect(fulllayer);
		painter->restore();
	
	   if (edit_enable) {  /* writteln modus icon */
				painter->save();
				QPixmap pixbg(":/img/icon.png");
				painter->drawPixmap(QPointF(boundingRect().width() - 40,8),pixbg);
				painter->restore();
			}
	
	  /* rect from frame root QTextDocument*/
	  QRectF doc_rect = boundingRect();
		QColor BackHightlight("#a6ffc7");
					 BackHightlight.setAlpha(140);
		QAbstractTextDocumentLayout::PaintContext CTX;    
		CTX.selections;
		 if (doc_rect.isValid()) {
					painter->setClipRect(doc_rect, Qt::IntersectClip);
					CTX.clip = doc_rect;
		 }
		CTX.palette.setColor(QPalette::Highlight,BackHightlight);
		CTX.palette.setColor(QPalette::HighlightedText,Qt::white);
		/* blink cursor from timer event ! */
		if (edit_enable) {
				if (cursortime) {  /* cursor blink vom timer QApplication::cursorFlashTime() */
				CTX.cursorPosition = cursor_position;
				} else {
				CTX.cursorPosition = -1;
				}
				
				if (C_cursor.hasSelection()) {
					QAbstractTextDocumentLayout::Selection Internal_selection;
					Internal_selection.cursor = C_cursor;
								QPalette::ColorGroup cg = cursorIsFocusIndicator ? QPalette::Active : QPalette::Inactive;
								Internal_selection.format.setBackground(CTX.palette.brush(cg, QPalette::Highlight));
								Internal_selection.format.setForeground(CTX.palette.brush(cg, QPalette::HighlightedText));
								Internal_selection.format.setProperty(QTextFormat::FullWidthSelection, true);
				   CTX.selections.append(Internal_selection);
				}
	  }
    _d->documentLayout()->draw(painter,CTX);
		/* _d = QTextDocument dispay editable modus yes ! */              
}


Verfasst: 30. April 2008 19:13
von upsala
Ein Ausschnitt aus dem Qt-Code, der aufgerufen wird, bevor der Cursor gezeichnet wird:

Code: Alles auswählen

painter->setPen(context.palette.color(QPalette::Text));

Verfasst: 1. Mai 2008 19:27
von patrik08
upsala hat geschrieben:Ein Ausschnitt aus dem Qt-Code, der aufgerufen
geht auch nicht ....

Code: Alles auswählen

if (edit_enable) {
				if (cursortime) {  /* cursor blink yes vom timer QApplication::cursorFlashTime() */
				painter->setPen(QPen(QBrush(contrastbackcolor),1));
				CTX.cursorPosition = C_cursor.position();
				} else {
				painter->setPen(Qt::NoPen);
				CTX.cursorPosition = -1;
				}
	  }

_d->documentLayout()->draw(painter,CTX);

gerne moechte ich QAbstractTextDocumentLayout erweitern um an table zelle und block format border zu geben wie die frame..

aber dass explicit was vor der klasse ist begreife ich nicht so recht...

Code: Alles auswählen

    explicit QAbstractTextDocumentLayout(QTextDocument *doc);
    ~QAbstractTextDocumentLayout();
dort unten ist viel was trolltech nicht dokumentieren will...

wenigstens habe ich nun einen guten ersatz fuer QTextControl was gut lauft ... und mann anpassen kann...

svn co http://fop-miniscribus.googlecode.com/s ... extEditor/ xx