QPlainTextEdit* edit = new QPlainTextEdit(this);
edit->setGeometry(*rect);
QPoint test
= edit
->viewport
()->mapToGlobal
(edit
->viewport
()->pos
());
qDebug() << test.x() << " " << test.y();
QPlainTextEdit* edit = new QPlainTextEdit(this);
QRect* rect = new QRect(100, 400, 200, 80);
edit->setGeometry(*rect);
QPoint test = edit->viewport()->mapToGlobal(edit->viewport()->pos());
qDebug() << test.x() << " " << test.y();
To copy to clipboard, switch view to plain text mode
Simple code; It will display "102 402" instead of "100 400" since it is the viewport's position, not widget position. I need to get the position of the whole widget, not the viewport.
In my code, I have a pointer to viewport though and need to get the widget's position using this.
The question is how to get rid of these 2 pixels. Just decreasing test.x and test.y by 2 is not a good idea since I believe this value is not constant for every PlainTextEdit widget.
Nevermind, made this post too fast. Managed to find out it on my own. Sorries.
Bookmarks