PDA

View Full Version : PlainTextEdit's position indicated by it's viewport's position



Grzyboo
28th July 2015, 22:28
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();


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.

prasad_N
29th July 2015, 18:10
edit->pos() is returning 100,400.