Hi all, I'm working on a shared editor and I need to make a label to follow a cursors position in the text.


- i tried with "ui->textEdit->viewport()->mapToGlobal(<textEdit cursor>);" -> it return me always the center of the window

- i tried to get the textEdit position and sum it to the position of the cursor as an offset -> but return the top left corner of the window

- i tried with "ui->textEdit->cursorRect() to get the actual cursor position -> but return the top left corner of the window

but nothing seems to work

Annotazione 2020-07-22 172840.png

i want the label to align to that orange line I draw

right now I ended up with apply an offset I set manually but aparently it vary with the computer the application is running on
Qt Code:
  1. void MainWindow::UpdateCursorPosition(std::string user, int x, int y) {
  2.  
  3. QLabel *label;
  4. if(usersCursors.find(user) != usersCursors.end()){
  5. label = usersCursors.at(user);
  6. // set label geometry to move it
  7. label->setGeometry(x + 21, y + 40,/*label->sizeHint().width() +*/ 1, label->sizeHint().height() + 10);
  8. }
  9.  
  10. }
To copy to clipboard, switch view to plain text mode