[solved] QTextEdit and QGraphicsProxyWidget - how to translate cursor coordinates?

  • I'm using a QTextEdit widget embedded in a QGraphicsScene with QGraphicsProxyWidget. I need to get the screen coordinates of the text cursor. If I do this with a non-embedded QTextEdit, I use something like:
    cursorRect = QRect(textEdit->mapToGlobal(textEdit->cursorRect().topLeft()), textEdit->cursorRect().size());@

    How does one do this with an embedded QTextEdit widget?


  • This works:

    QGraphicsProxyWidget *proxyWidget = textEdit->graphicsProxyWidget();
    QGraphicsScene *graphicsScene = proxyWidget->scene();
    QGraphicsView *graphicsView = graphicsScene->views().first();

    cursorRect = graphicsView->mapFromScene(proxyWidget->mapToScene(QRectF(textEdit->cursorRect()))).boundingRect();

    cursorRect = QRect(graphicsView->mapToGlobal(cursorRect.topLeft()), cursorRect.size());

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.