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
void MainWindow::UpdateCursorPosition(std::string user, int x, int y) {
if(usersCursors.find(user) != usersCursors.end()){
label = usersCursors.at(user);
// set label geometry to move it
label->setGeometry(x + 21, y + 40,/*label->sizeHint().width() +*/ 1, label->sizeHint().height() + 10);
}
}
void MainWindow::UpdateCursorPosition(std::string user, int x, int y) {
QLabel *label;
if(usersCursors.find(user) != usersCursors.end()){
label = usersCursors.at(user);
// set label geometry to move it
label->setGeometry(x + 21, y + 40,/*label->sizeHint().width() +*/ 1, label->sizeHint().height() + 10);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks