Hallo,
ich versuche vergeblich die Position des Textcursors in einem QTextEdit
zu bestimmen.
QRect rect = textedit->cursorRect();
als auch
QTextCursor textcursor = textedit->textCursor();
QRect rect = textedit->cursorRect(textcursor);
scheitern.
Kann mir jemand weiterhelfen?
LG, Hannes
Position des Textcursors in Pixel
Ich brauche QGraphicsView um richt text seiten zu zeigen im programm
http://www.qt-apps.org/content/show.php ... tent=67552
Dort mache ich es so:
funktioniert wo keine tabellen sind & textframe! (also immer im block paragraph)
Den cursor muss ich dan noch um y mappen auf die jeweilige seiten anzahl distanz...
http://www.qt-apps.org/content/show.php ... tent=67552
Dort mache ich es so:
funktioniert wo keine tabellen sind & textframe! (also immer im block paragraph)
Code: Alles auswählen
QLineF TextProcessor::BlinkCursorLine()
{
QLineF CursorDrawLine(QPointF(0,0),QPointF(0,10)); /* error line */
/* QTextDocument *_d; */
const QRectF xxtmp = _d->documentLayout()->blockBoundingRect(textCursor().block());
QTextFrame *Tframe = _d->rootFrame();
root_format = Tframe->frameFormat();
QTextLine TTline = currentTextLine(textCursor());
if ( TTline.isValid() ) {
int pos = textCursor().position() - textCursor().block().position();
const qreal TextCursorStartTop = TTline.lineNumber() * TTline.height() + xxtmp.top();
const qreal TextCursorStartLeft = TTline.cursorToX(pos) + root_format.leftMargin() + root_format.padding();
CursorDrawLine = QLineF(QPointF(TextCursorStartLeft,TextCursorStartTop),QPointF(TextCursorStartLeft,TextCursorStartTop + TTline.height()));
}
return CursorDrawLine;
}
QTextLine TextProcessor::currentTextLine(const QTextCursor &cursor)
{
const QTextBlock block = cursor.block();
if (!block.isValid())
return QTextLine();
const QTextLayout *layout = block.layout();
if (!layout)
return QTextLine();
const int relativePos = cursor.position() - block.position();
return layout->lineForTextPosition(relativePos);
}
.........................
speack português italiano deutsch english castellà qt
speack português italiano deutsch english castellà qt
@patrik
danke, ich schau es mir mal an.
@upsala,
Weil ich stets die Werte -4,2,7,11 für left, top, right, bottom, erhalte.
Lediglich wenn ich die Tab Taste drücke erhalte ich vernünftige Werte.
Allerdings wüßte ich ja nur gern, an welcher koordinate (pixel) der Cursor
sich befindet, damit ich dann dies Position zum Öffnen eines Fenster verwenden kann.
Gruß, Hannes
danke, ich schau es mir mal an.
@upsala,
Weil ich stets die Werte -4,2,7,11 für left, top, right, bottom, erhalte.
Lediglich wenn ich die Tab Taste drücke erhalte ich vernünftige Werte.
Allerdings wüßte ich ja nur gern, an welcher koordinate (pixel) der Cursor
sich befindet, damit ich dann dies Position zum Öffnen eines Fenster verwenden kann.
Gruß, Hannes
Danke an alle
Jetzt funktionieren
bei mir auch.
Liegt wohl an dem Code der noch dazwischen liegt.
Also muss ich nun mal die Ursache suchen.
LG, Hannes
Jetzt funktionieren
Code: Alles auswählen
QTextCursor textcursor = textedit->textCursor();
QRect rect = textedit->cursorRect(textcursor);
Liegt wohl an dem Code der noch dazwischen liegt.
Also muss ich nun mal die Ursache suchen.
LG, Hannes